unbound imagination - a blog about programming

Javascript Dependency Manager and Google AJAX Libraries

May 29, 2008

On Tuesday, Google released a new service where they host popular javascript libraries such as prototype and jQuery. This allows you to link to their copy of the libraries instead of your own so you can reduce the load on your server and speed up the client's experience.

They plan on archiving all stable versions of each library and allowing you to choose which you want to link to. They also provide compressed versions of all the libraries except scriptaculous and prototype (I'm not sure why only those two are left out).

Anyway, I've added support for using the Google copy of these libraries into my javascript dependency manager plugin. To use it, upgrade to the newest version of the plugin and create an initializer with the following code:

   1  JavascriptHelper::JavascriptHelperConfig.use_google_ajax_libs = true

Now when you include prototype, jQuery or any of the other supported libraries using the javascript dependency manager plugin, it will refer to the Google hosted file. By default the Google hosted libraries are not used, so users who want to stick to their own ways can continue doing so without any changes.

You can specify library versions and preference for compressed versions in the initializer as well, view the readme for details on how to do that.

Comments

posted by Star Trader on 05/29/08 10:40 PM PDT

I saw this come down the pipe on slashdot and the tinfoil hat folks gave it a good thrashing. I thought it was a great idea myself, especially from Google, but I wonder if you have any comments about the privacy implications of doing this?

posted by Rob Olson on 05/30/08 12:36 AM PDT

I remember a point last night when my roommate stood in my doorway and ranted a little bit about how it didn't make sense to him that Google was hosting javascript libraries.

I guess he got over it though because the next day he added support for them to his Rails plugin. :-p

posted by Arya Asemanfar on 05/30/08 01:10 AM PDT

Star Trader,

After your comment, I took a look at this Slashdot post and read through the comments. My initial opinions, as revealed in the comment above by my roommate, were of confusion and denial. I didn't see how this new service was going to help anything.

After thinking about it some more and reading around, I decided that this is worth taking advantage. Most the privacy issues mentioned in the Slashdot comments were preposterous, Google isn't going to get away with slipping in spyware code or malicious code into any of these libraries; it would be noticed almost instantly by the many masses whose eyes are all over this. As for usage statistics: so many sites already use Google Analytics or Google AdSesne that providing cached javascript libraries to gain an extra negligible amount of usage statistics doesn't make sense.

So to address my initial opinion of confusion, I'm not exactly sure why Google chose to offer this to people, but part of me thinks it's simply the work of a few developers' twenty percent time.

Lastly, to those who think Google offering this is a bad idea: please feel free to explain why it makes sense to have thousands upon thousands of copies of the same file hosted on different servers under different hosts. You check your cache, how many copies of prototype.js do you have?


Leave a Comment