Simon
Simon

Reputation: 2623

W3 Total Cache not loading CDN jquery before cached javascripts

I see that there is not much help regarding this plugin but here goes anyway.

I am sure someone else has hit this issue before.

I have WP 3.3.2 and running W3 Total Cache 0.9.2.4

These are the settings for W3 Total Cache — http://www.diigo.com/item/image/2no8j/qgct

I am loading my javascripts via a hook as shown:

  add_action( 'wp_enqueue_scripts' , 'woodworks_load_scripts', 11 ); 

  function woodworks_load_scripts() {

  global $post, $Post_UI_Tabs;

  $js_dir = STYLESHEET_DIR . 'js/';
  $admin_dir = STYLESHEET_DIR . 'admin/';
  $jquery_ui = JQUERY_UI;


  wp_deregister_script('thickbox');
  wp_deregister_script('swfobject');
  wp_deregister_script('jquery');

  wp_register_script('jquery', 'http://code.jquery.com/jquery-latest.min.js', false, '1.7.2', true);

  wp_enqueue_script('jquery');

  if( woodworks_has_tabbed_content( $post ) ){
     wp_enqueue_script('jquery.ui', "{$jquery_ui}", array('jquery'), 1, true);
     $Post_UI_Tabs->has_tabs = true;
  }

  if( 'award' != get_post_type( $post->ID ) ) {
     wp_enqueue_script('main', "{$js_dir}main.js", array('jquery'), 1, true);
     wp_enqueue_script('supersize', "{$js_dir}supersized.3.1.3.min.js", array('jquery'), 1, true);
  }

  if( 'award' == get_post_type( $post->ID ) ){
     wp_enqueue_script('jquery.cycle.all', "{$js_dir}jquery.cycle.all.js", array('jquery'), 1, false);
  }


  if( is_front_page() ){
     wp_enqueue_style( 'home', STYLESHEET_DIR . 'stylesheets/home.css', array(), 1, 'all' );
     wp_enqueue_script('jquery.cycle.all', "{$js_dir}jquery.cycle.all.js", array('jquery'), 1, true);
  }

}

You can compare woodworks.signalsinteractive.com ( has caching ) vs woodworks.org ( uncached ) and see the source differences.

The issue is that the cached jQuery is called after the cached versions. So it will cause a jQuery undefined error.

Upvotes: 0

Views: 4881

Answers (2)

Naser Nikzad
Naser Nikzad

Reputation: 941

For me the solution was to add jquery main file

https://www.example.com/wp-includes/js/jquery/jquery.js?ver=1.12.4-wp

at the top of the list for minification.

Upvotes: 0

rtvenge
rtvenge

Reputation: 61

In order for me to fix this issue, I had to minify jquery into your concatenated/minified js file. This is how I did it:

  1. In General Settings, set minify mode to Manual.
  2. Go to minify tab, and under JS File Management, add the jquery URI to File URI (ex: http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js). Set to "All Templates" and "Embed in ".

This fixed it for me, however you are no longer using the Google CDNed jquery.

Upvotes: 3

Related Questions