Google's JavaScript API Loader
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.latitudegoogle.loader.ClientLocation.longitudegoogle.loader.ClientLocation.address.citygoogle.loader.ClientLocation.address.countrygoogle.loader.ClientLocation.address.country_codegoogle.loader.ClientLocation.address.region
If a location cannot be determined from the visitors IP address, the google.loader.ClientLocation variable will be null.
Tweet
add to del.icio.us
| Tags: google, javascript, geo, latitude, longitude, prototype, scriptaculous
Related Entries
- Calculating Distance in Miles from Latitude and Longitude - January 18, 2007
- Howto Build Server Side AJAX Suggestions with script.aculo.us - December 6, 2006
- Geolocation API for Adobe AIR? - October 8, 2008
- GoogleBot Runs AJAX? - December 6, 2006
- Uploading Files Like GMail Attachments - October 6, 2006
Trackbacks
Comments
(if you use the loader you have to put all your code in an onload handler and that might be annoying)
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.
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.
Post a Comment
Recent Entries
- Writing Secure CFML cfObjective 2013 Slides
- Upgrading to Java 7 on Linux
- J2EE Sessions in CF10 Uses Secure Cookies
- Learn about ColdFusion Security at cfObjective 2013
- Session Loss and Session Fixation in ColdFusion
- FuseGuard 2.3 Released
- CKEditor Spell Checker Plugin
- Adobe Says Go Ahead and Upgrade your ColdFusion JVM





