Utilize Google’s Ajax Libraries API

The problem: loads of websites around the internet using the exact same javascript file. The file is a whopping 100KB in size. Since this same file resides on each website’s server, the file is downloaded and cached for each individual website. Lots of load time for same file.

The solution: Google AJAX Libraries APIs. Google hosts these frequently used files, including the newest versions (and legacy versions) of jQuery MooTools, YUI, Dojo, Prototype, and more. Why use Google’s AJAX Libraries API? Benefits include:

  • Google’s servers can serve the file faster than your shared hosting server.
  • Since the file is always being pulled from the same place, the more sites that use that file, the more likely that file is already in the user’s cache. Thus, your website loads faster.
  • You save bandwidth.

Here’s how you implement google.load().

<!-- Always need this javascript -->
<script src="http://www.google.com/jsapi" type="text/javascript"></script>

  google.load("jquery", "1.3.2");
  google.load("jqueryui", "1.7.2");
  google.load("prototype", "1.6.1.0");
  google.load("scriptaculous", "1.8.3");
  google.load("mootools", "1.2.4");
  google.load("dojo", "1.3.2");
  google.load("swfobject", "2.2");
  google.load("yui", "2.8.0r4");
  google.load("ext-core", "3.0.0");

That’s all there is to it. Pass Google the library and version you desire and Google does the rest.

  • Share/Bookmark

You can follow any responses to this entry through the RSS 2.0 feed.