Here’s a quick tip that will benefit your WordPress blog or website. When you install WordPress, all required JavaScript and code libraries are hosted on the local server that WordPress is installed on. In most cases, that’s ok. But if you want to speed up your sites, using Google Hosted JavaScript libraries can help.

You see, Google Hosted Libraries is a content distribution network (CDN) for most popular open-source JavaScript libraries. It contains JQuery and JQuery UI and many others that already come with WordPress. So, instead of pulling those libraries from your local server, why not use Google Hosted Libraries instead.

If you use Google Hosted Libraries, visitors to your sites will pull those scripts from Google’s servers instead of your local server, which in most cases faster than yours.

Objectives:

  • Use Google Hosted JavaScript Libraries in WordPress
  • Enjoy!

To get started, login to WordPress as administrator and go to Appearance –> Editor. Then select the function.php file for your theme to open. (Theme Functions)

When the file opens, copy and paste the content below into it and save. At the time of this post, the latest version of JQuery and JQuery UI were 1.8.2 & 1.8.23 respectively. You may have to change the version URL and # when new ones are added.

if( !is_admin()){
wp_deregister_script('jquery');
wp_register_script('jquery',  'https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js', false, '1.8.2');
wp_enqueue_script('jquery');
}

if( !is_admin()){
wp_deregister_script('jquery-ui');
wp_register_script('jquery-ui', ("https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"), false, '1.8.23');
wp_enqueue_script('jquery-ui');
}

 

jquery

 

Restart your webserver (apache) and test. Use Webpagetest.org .

 

jquery_1

 

Google Hosted Libraries can be found on this site