Load jQuery with Google Libraries API

google load jquery

Usually if you want to use jQuery you need to download the latest package, save the .js file in your js/ folder and then include the link in your page header. This can become time consuming especially when you need to test different versions of jQuery for compatibility with plugins or code you are developing. It also is annoying to keep upgrading to the latest version each time they release a new version (usually every few months or so). Here comes Google to the rescue (once again!) by offering a Library API which can load the latest version (or any version) of pretty much any JavaScript Library going. This saves you downloading them onto your own host each time you use a library. Dynamically Load jQuery Library Using Plain JavaScript.

The Libraries API provides your applications with stable, reliable, high-speed, globally available access to all of the most popular, open-source JavaScript libraries. Your application can use our very flexible loader

google.load()

or direct, path-based access to the scripts.

Using Google API to Dynamically Load jQuery

Step 1 Get your Google API key

Step 2 Put this code in your header:

<script type="text/javascript"
src="https://www.google.com/jsapi?key=INSERT-YOUR-KEY"></script>

Step 3 Put this code in your header:

<script type="text/javascript">google.load("jquery", "1.6.1");></script>

Or you can use a direct link:

No Strings attached Include, Latest Versions

//GOOGLE APIs
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
//JQUERY.COM
<script src="http://code.jquery.com/jquery-latest.js"></script>

See how to fall back to your own local jQuery package if the Google one doesn’t load (not likely).

Tip: You can use google.load(“jquery”, “1″);  to automatically load the latest version of jQuery.

The jQuery package details

name: jquery
latest version: 1.6.1 (view older versions)1.2.3, 1.2.6, 1.3.0, 1.3.1, 1.3.2, 1.4.0, 1.4.1, 1.4.2
load request: google.load(“jquery”, “1.6.1″);
extras: uncompressed:true (as in google.load(“jquery”, “1.6.1″, {uncompressed:true});
path: https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js
path(u): https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/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…

Other supported Libraries in the Google API

  google.load("chrome-frame", "1.0.2"); 
  google.load("dojo", "1.5"); 
  google.load("ext-core", "3.1.0"); 
  google.load("jquery", "1.6.1"); 
  google.load("jqueryui", "1.8.6"); 
  google.load("mootools", "1.3.0"); 
  google.load("prototype", "1.6.1.0"); 
  google.load("scriptaculous", "1.8.3"); 
  google.load("swfobject", "2.2"); 
  google.load("yui", "2.8.2"); 
  google.load("webfont", "1.0.15");
Source: http://code.google.com/apis/libraries/devguide.html
:)