Strictly speaking the Google Ajax libraries don't contain only Ajax libraries, but they are very useful for a variety of reasons. Google host a variety of different JavaScript libraries which you can link to on your pages rather than download the library and host it on your server. You can use MooTools, JQuery, Prototype/Scriptaculous, Dojo and even the Yahoo! User Interface Library.
How To Use Them
Using the Google Ajax libraries on your own site is quite easy, and you can do it in a number of different ways.
Normally, you would download the latest and greatest version of your chosen library and upload it to your site. Here is an example using the MooTools.
<script type='text/javascript' src='http://www.hashbangcode.com/mootools.js'></script>
You can include this via Google using the following.
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/mootools/1.2.1/mootools-yui-compressed.js'></script>
If you are working on a development server you can also include the uncompressed version so that you can see where any errors are coming from.
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/mootools/1.2.1/mootools.js'></script>
If you want to download version 1.11 instead of version 1.2.1 by changing the folder:
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/mootools/1.11/mootools.js'></script>
You can also use the google.load() function to include the library you want with a single function call.
<script src="http://www.google.com/jsapi"></script>
<script>
google.load("mootools", "1.2.1");
</script>
Ease Of Use
You have to admit that this method of including JavaScript is much easier than downloading the library manually, uploading it and then sorting the script tags out.
Quick Downloads
The first benefit of using this service is that users will not have to wait very long in order to download the JavaScript libraries that your site relies on to work. This is because they are downloading it from Google and not your site and therefore can pool upon the massive resources that Google have.
Concurrent Connections
Your browser can only open a certain number of connections to a domain; this is partly due to how browsers work but also due to how servers work. If you host your JavaScript libraries with Google then your browser will be able to run off and get them whilst it is downloading your page making the page load a little faster.
Better Caching
Rather than repeatedly downloading files from a site over and over again a browser will try to minimise this by only downloading what it hasn't downloaded already. This is fine if you spend all of your time on a single site, but most people don't and they will therefore download the same version of the same JavaScript library over and over again. This happens even if the server has aggressive caching turned on. By hosting your libraries with Google you basically allow a user who has visited a site using the same library as you to reuse the file they downloaded there on your site.
Don't Use On Your Intranet
There is one small issue if you are using this sort of thing on an Intranet system in that it will create unnecessary network traffic from your network. This method can also leave Intranet systems utterly useless if your Internet connection goes down for whatever reason. Holding your JavaScript libraries locally will mean that your systems can continue to work, even if you are cut off from the outside world.
Word Of Warning
Some countries actively block connections to some sites; especially Google. So if you do include JavaScript libraries like this then the chances are that someone in Iran or China will certainly not be able to view any JavaScript components and might even get a load of authentication errors.
More Information
For more information on the different libraries available take a look at the Google Ajax Libraries page.
Add new comment