This Is Locomotion - Design, Code, and News

Using google.load() to optimize web page load times

One of the problems in developing large feature-rich AJAX web applications is that page load times can really suffer once you start using the larger JavaScript libraries such as JQuery, MooTools, Prototype, or SWFObject. Most of these libraries are larger than 50Kb in size and once you start combining libraries you can easily add 100Kb+ to your page loads.

At Simple Station we are adding the finishing touches to optimizing our first big open source application and we have been looking for every possible way to optimize the JavaScript we use. Today I came across google.load(), which promises to significantly decrease JavaScript load times.

The benefits of using Google to provide these libraries instead of your own server include:

  • Google’s huge CDN (content delivery network) can deliver the file much faster than your own server(s). Since Google has large data centers all over the world, these files will be served from data centers geographically closer to your users. This helps to reduce network latency and works to increase reliability, scalability, and website speed.
  • The more sites that include Google’s google.load() API the greater the chance that a user has already has the file cached, thus enabling your site to load faster as the script will not need to be downloaded.
  • You save bandwidth as you no longer have to serve the file(s).
  • The versioning system that Google has created makes it easy to include specific versions of these libraries.

All you need to utilize Google’s google.load() technology is this JavaScript snippet:

<script src="http://www.google.com/jsapi" type="text/javascript"></script>
google.load('mootools', '1.2.1');
google.load('jquery', '1.3.1');
google.load('jqueryui', '1.5.3');
google.load('prototype', '1.6.0.3');
google.load('scriptaculous', '1.8.2');
google.load('dojo', '1.2.3');
google.load('swfobject', '2.1');
google.load('yui', '2.6.0');

View the complete list of ajax libraries hosted by Google.

2 Responses to “Using google.load() to optimize web page load times”

  1. Roman says:

    You better know it, if too many people will start doing this, Google will insert code into these libraries that will do things behind your back and you will not be able to control it.

    When you use other people’s code, if they decide to do something, like read your data, see what the user is doing and report it back to the code owners, well, don’t be surprised then.

Trackbacks/Pingbacks

  1. ... Using google.load() to optimize web page load times Tags: css, google, javascript, jquery, performance, ruby, testing Comment (RSS)  |  Trackback ...