Google AJAX Libraries API

Today Dion Almaer announced the Google AJAX Libraries API. This is a great resource for developers using any of the popular JavaScript frameworks including Prototype, Script.aculo.us, jQuery, Dojo, and MooTools. Rather than downloading it to your own server and hosting it from there, you can request your preferred JavaScript library from ajax.googleapis.com:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js">
</script>

The greatest benefit in my opinion is that any developer can leverage Google’s CDN to deliver the bulk of their JavaScript. From YSlow and my book I received a lot of feedback that Rule 2: Use a CDN was out of reach for many developers. I use jQuery in one of my personal projects and serve it on my hosted web site from one geographic location. Ouch. Being able to move that 21K closer to my users is great.

Other benefits: There’s a community benefit here. As more and more sites move to these files users who navigate across those sites may only have to download the file once and read it from cache for all the other sites. Also, the versions served up by Google have an Expires date set one year in the future and are gzipped. Three of the libraries also have a minified version which reduces size another 13-21% by minifying the JavaScript before gzipping.

Library Original Gzipped Minified &
Gzipped
jQuery 100K 30K (30%) 17K (17%)
MooTools 183K 49K (27%) 19K (11%)
Dojo 294K 90K (31%) 29K (10%)

All of these performance optimizations are great to see. YUI, another great alternative, is already offered via Yahoo!’s CDN from yui.yahooapis.com with similar performance features. Already there are nearly 50 comments on the Ajaxian post. Performance is a hot topic now as we push browsers to their limits. Services like this are just what’s needed to help us make the user experience as fast as possible.