How to Make jQuery Loading Faster in WordPress


By default, WordPress load its own copy of jQuery file located in wp-includes/js/jquery/jquery.js, calling wp_enqueue_script(‘jquery’). But loading the jQuery from Google Hosted Libraries will make the web faster, providing numerous potential performance benefits:

  • Increases the chance that a user already has these files cached
  • Takes load off your server
  • Google’s servers are set up to negotiate HTTP compression with the requesting browser

Here’s an easy way to do it. Paste the code below into your functions.php file:

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

Once you saved the file, WordPress will load jQuery from Google CDN, making the web faster.

Leave a Reply

Your email address will not be published. Required fields are marked *