Google's JavaScript API Loader

November 26, 2008

Did you know Google's JavaScript Loader API can serve up popular javascript frameworks such as jQuery, and Prototype using their content distribution network? It works like this:

<script src="" language="javascript"></script>
<script language="javascript">
google.load("prototype", "1.6");
google.load("scriptaculous", "1.8.2");

You can see a full list of supported API's here.

Their JavaScript API now gives you access to your visitor's location, it sets a variable google.loader.ClientLocation, and populates it with City, Region/State, Country, Latitude, Longitude.

Here's an example:

<script src="" language="javascript"></script>
<script language="javascript">
if (google.loader.ClientLocation != null) {
document.write("Your Location Is: " + + ", " + google.loader.ClientLocation.address.region);
} else {
document.write("Your Location Was Not Detected By Google Loader");

The avaliable properties of the google.loader.ClientLocation object are:

  • google.loader.ClientLocation.latitude
  • google.loader.ClientLocation.longitude
  • google.loader.ClientLocation.address.country_code
  • google.loader.ClientLocation.address.region

If a location cannot be determined from the visitors IP address, the google.loader.ClientLocation variable will be null.

Related Entries

10 people found this page useful, what do you think?


You don't necessarily need to load the ajax libs (jQuery,prototype etc)through jsapi loader you can link directly to them e.g. <script type="text/javascript" src=""></script> (if you use the loader you have to put all your code in an onload handler and that might be annoying)
I wonder if relying on an external CDN (even if it is google who you'd think have fantastically reliable infrastructures) would be good for your site. Especially if you are using heavy javascripts which do a lot 'onload'. This might provide a bad user experience in times where the network to google is a little slow. With compression and expires headers you may really not be saving all that much. I guess it's a case by case basis. I think it's great, but I don't think I'd use it for any of my sites.
@Mike - I think the other advantage is that browsers cache this information based on the link, so the more websites that link to Google's version, the more likely the person who hits your site will have the file already cached locally, thus avoiding the payload penalty.
@Michael I certainly understand your concerns, there are probably a lot of cases where you wouldn't want to use google's version. As Andrew points chances are performance would be better using Googles version due to caching, and their network. However if you are on an intranet using downloading google's version would probably take longer. Also there is a security risk to including a javascript file from a foreign domain. If someone hacked google, or if google had an evil employee they could manipulate your website, and very easily steal sessions. It's actually quite a risk. I may post some of these thoughts in another blog entry.
Thanks to Google API! The example can be found on by viewing the source codes.
I think someone must be quite stupid to use Google Javascript. First the load and bandwidth it reduces is so small that it can be hardly measured today. Specially with server and hardware getting more powerful each day. You can load millions of request from a single server, so what would you save a 000000.1 load from using Googles javascript? Not to mention bandwidth. Its a penalty most people are going to use, just because they are to lazy to upload the javascript source to their servers, since they happen to be free. Just see how websites load slow because of Analytics, not to mention Gmail had several outages this year. All it takes is a little slow down to put your website to sleep. Imagine if each content on a page would rely on an external server. Each image, each javascript, each bit on a different server, it would be a mess. I would not even start promoting things like this. Its just a bad idea.
Why gmail browser cookies not response .and any switch off .retrun on browser ?why plz help me browser cookies capsul on
4ty 56y56 556 565 65656 565656 56565 656 654

Post a Comment


Spell Checker by Foundeo

Recent Entries


did you hack my cf?