CDN

How to Remove WordPress’ jQuery and Use Google’s CDN Version Instead?

Why Use Google’s CDN?

The three most commonly cited reasons to dequeue WordPress’ bundled version of jQuery in favor of Googles are:

  1. Decreased Latency.
  2. Increased Parallelism.
  3. Better Caching.

Why NOT Use Google’s CDN?

  1. WordPress takes great care to make sure its bundled libraries are fully compatible with other bundled scripts. jQuery is loaded in “no conflict” mode to prevent any potential script collisions over the $ variable in the global namespace.
  2. If you load jQuery 1.9 yourself from Google’s CDN, you’ll miss out on the jQuery Migrate plugin and end up breaking several themes and plugins that depend on these deprecated APIs.
  3. Also, WordPress is taking steps to prevent you from dequeueing jQuery on the back end at all.

Source: Don’t Dequeue WordPress’ jQuery

Then, How to Remove WordPress’ jQuery and Use Google’s CDN Version Instead?

function jquery_cdn() {
   if (!is_admin()) {
      wp_deregister_script('jquery');
      wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js', false, '1.8.3');
      wp_enqueue_script('jquery');
   }
}
add_action('init', 'jquery_cdn');

Comment by Nathan Rice:

This is almost sure to cause warnings if you have WP_DEBUG on. The reason being that wp_register_script should only be called on the wp_enqueue_scripts action hook.

Sources:
How to load jQuery from Google CDN
Replace default WordPress jQuery script with Google Library

Scroll to Top