Quantcast
Viewing all articles
Browse latest Browse all 10

Use Google-Hosted jQuery in Your WordPress Theme

How many sites use popular JavaScript libraries like jQuery? A lot. That’s why Google hosts many of them on their speedy CDN, so browsers only have to download jQuery or Prototype once in a day, instead of once per site.

How can your WordPress-powered site benefit from this? Digging into WordPress has the answer:

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

This little snippet goes in your functions.php, where it deregisters WordPress’s internal copy of jQuery and references Google’s. Unfortunately, it’s not set up for the handy no-conflict mode that lets you use Prototype scripts on the same blog.


Viewing all articles
Browse latest Browse all 10

Trending Articles