Let google host your Jquery (faster cdn page load) – wordpress

Let google host your Jquery (faster cdn page load) – wordpress

Google hosts a couple of well known scripts, like prototype, mootools and jquery. As the latest version of Jquery is ~90kb, it is necessary that it loads fast.

The best way to achieve that is let google host your scripts. In this way, wherever in the world your site is visited, the nearest google server will serve the script and will be much faster than a visitor for example from Belgium visits a site hosted in America.

This google page gives us the power to choose the scripts: http://code.google.com/intl/nl-BE/apis/libraries

This is the code of Jquery:

name: jquery
load request: google.load(“jquery”, “1.6.4”);
extras: uncompressed:true (as in google.load(“jquery”, “1.6.4”, {uncompressed:true});
path: https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js
path(u): https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.js
site: http://jquery.com/
note: 1.2.5 and 1.2.4 are not hosted due to their short and unstable lives in the wild…

What you need to do now is integrate this in your wordpress website. Every theme does that on his own, and you have to bypass that. So we are putting this line of code in the very source of every wordpress installation (not depending on the theme).

Go to the script loader.php file in your wp-includes folder and search for this line:
$scripts->add( ‘jquery’, ‘/wp-includes/js/jquery/jquery.js’, false, ‘1.6.1’);

Make it this:
$scripts->add( ‘jquery’, ‘https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js’, false, ‘1.6.4’);

Tadaaa ! :)

VN:F [1.9.22_1171]
Rating: 4.0/5 (1 vote cast)
About Benwake

I'm Ben, working as a System Engineer for a big company. Webdesign is one of my biggest passions, along with a lot of other hobby's. I love to share my interests and I hope you'll enjoy this website. More Posts

2 Comments to “Let google host your Jquery (faster cdn page load) – wordpress”

  1. Alex Varsakopoulos // June 21, 2012 at 10:43 am // Reply

    I have my google-apps domain and when all the users and I try to reply to an email we get this:

    Script: https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js:3

    And it freezes for a minute, and then repeats itself. Very frustrating. We are a school and I don’t want my students dissuaded. Any hints as to what’s causing it?

Leave a comment

Your email address will not be published.

*