Google's JavaScript API Loader

web

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="http://www.google.com/jsapi" language="javascript"></script>
<script language="javascript">
google.load("prototype", "1.6");
google.load("scriptaculous", "1.8.2");
</script>

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="http://www.google.com/jsapi" language="javascript"></script>
<script language="javascript">
if (google.loader.ClientLocation != null) {
document.write("Your Location Is: " + google.loader.ClientLocation.address.city + ", " + google.loader.ClientLocation.address.region);
} else {
document.write("Your Location Was Not Detected By Google Loader");
}
</script>

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

  • google.loader.ClientLocation.latitude
  • google.loader.ClientLocation.longitude
  • google.loader.ClientLocation.address.city
  • google.loader.ClientLocation.address.country
  • 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?

Trackbacks

Trackback Address: 683/A5D8E5F1B5F8F56AE0E479FC72C171E9

Comments

On 11/26/2008 at 4:08:06 PM UTC Akeem wrote:
1
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="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>

(if you use the loader you have to put all your code in an onload handler and that might be annoying)

On 11/27/2008 at 1:21:25 PM UTC Michael Sharman wrote:
2
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.

On 12/01/2008 at 4:58:17 PM UTC Andrew K wrote:
3
@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.

On 12/02/2008 at 9:53:14 AM UTC Pete Freitag wrote:
4
@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.

On 10/13/2009 at 9:59:33 AM UTC Poon wrote:
5
Thanks to Google API! The example can be found on http://checkbrowser.info by viewing the source codes.

On 12/01/2009 at 4:35:08 AM UTC henry wrote:
6
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.

On 10/28/2012 at 9:04:35 AM UTC DR SUMADHUR MALHOTRA wrote:
7
Why gmail browser cookies not response .and any switch off .retrun on browser ?why plz help me browser cookies capsul on

Post a Comment




  



Spell Checker by Foundeo

Recent Entries



foundeo


did you hack my cf?