Wednesday, April 1, 2009

Libraries On Demand: Google CDN based Ajax/JavaScript Libraries API

In my previous blog “Eclipse On Demand: Yoxos”, had described about the distribution service to ease out the hassles of configuring/maintaining a integrated development environment for specific project need considering the fact as not all projects are the same. In similar lines, here I will be discussing on using CDN for providing a means to access common Ajax/JavaScript framework libraries that are most widely used and we will not digg into using different Ajax frameworks.

By the way, what is CDN?

CDN stands for Content Distribution Network or Content Delivery Network, a system of computers networked together across internet that delivers content to end users for improving maintainability, performance, scalability etc. There are many CDN groups like Google, Yahoo, AOL, JSLoader etc available in market and here we will take on with using Google's CDN capabilities.

Google Ajax Libraries API

One such service is the Google Ajax Libraries API providing a loading architecture for most of the open source JavaScript libraries such as Dojo, Prototype, Script.aculo.us, jQuery, Yahoo UI, Mootools etc. Through this, Google provides the infrastructure upon collabrative decisions with the providers to access these libraries directly from its server thus providing developers the following advantages.

1. Hosting: Hosting of libraries is no longer a hassle as is maintained at a single location from Google. Thus no installation needed at the host end and saves the bandwidth too.

2. Caching: Setting of correct cache headers for those libraries that makes them downloadable as neccessary so that developers need not work on caching logic. Prevents file duplication in the browser cache.

3. Versioning: Staying up to date with the most recent available stable release with all bug fixes etc., Also provides minified versions.

4. Compression: Why to send them as such when certain browsers accepts the GZIP compression techniques. So GZIP compression is taken care automatically.

5. Responsiveness: Faster response as Google servers are fast and also has a distributed CDN across the globe at points nearer to the user.

6. Maintainability: Maintainability of libraries is minimized as content is downloaded only once instead of having each user download a private copy.

Two ways to load the appropriate libraries from Google:

#1. Access via Ajax APi loader. That is, using google.load().

Example:
...
<script src="http://www.google.com/jsapi"></script>
<script>
// Loading DOJO libraries
google.load("dojo", "1.3.0");
</script>
...

#2. Access directly using standard script tags

Example:
...
// Loading DOJO libraries
<script src=http://ajax.googleapis.com/ajax/libs/dojo/1.3.0/dojo/dojo.xd.j></script>
...

For more informations,

http://code.google.com/apis/ajaxlibs

http://code.google.com/apis/ajaxlibs/documentation/#AjaxLibraries

YouTube: