Google AJAX Libraries API

Do you use a JavaScript library — such as jQuery, Prototype, or MooTools — on one (or more) of your websites? That probably adds a good 18-120 kilobytes to your pages’ total size, adding more time to users’ download time.

Now, how many websites use that same framework? How many websites make use of jQuery, or example? A lot. That means any given user could be downloading the JavaScript files multiple times in a day, as different sites require it. What a waste of time and bandwidth.

Google has an interesting solution. They host multiple versions of several major JavaScript libraries on their servers for web developers to take advantage of. This offers several advantages. Their servers are quick and have wide pipes allowing for very fast downloads, for one. The real benefit is caching.

If a user visits several sites that reference jQuery (or another library) from Google, their browser caches the file and will only load it once, reusing the cached file on the other sites when they are loaded. This is because you’re referencing a file from ajax.googleapis.com instead of your own domain, and if multiple sites reference it, the browser remembers it already downloaded the file and uses the local copy.

The libraries available at the present are:

  • jQuery
  • jQuery UI
  • Prototype
  • script.aculo.us
  • MooTools
  • Dojo
  • SWFObject
  • Yahoo UI Library

To reference one, you simply call the JavaScript file as you normally would, but put the URL on Google’s servers instead of your own. For example, to load jQuery 1.3.0 you would use the following:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>

Simple, and a good way to cut down on page load time. The only downside is, if Google were to have problems with the servers that host the scripts, we would be looking at a web-wide lack of scripts that may be critical to the operation of some sites. Google is known to be fairly reliable, but you never know, it’s always possible that the supposedly impossible could happen. Then we would have a problem like the Amazon S3 outage last year, where scores of sites were affected. (Twitter’s avatars went AWOL, SmugMug had photos not showing, some podcasts weren’t downloadable, etc..)

  • http://infobets.net infobets

    Never enough about knowledge
    http://infobets.net
    Education is very good and many knowledge