the open web, web development, and more

Wednesday, May 28, 2008

Google Hosting JavaScript Libraries - But Don't Forget the Hash!

JavaScript libraries are great. Anyone that has done a significant amount of JavaScript development knows that using a library is the only sane way to develop an application. However, the downside has always been that the hefty size of the libraries leads to slower loading applications.

I've often discussed with colleagues that a potential solution is to have a "mega-performant" 3rd party site host the libraries. This way any website using the libraries could source them from the same domain leading to a higher chance that your users would already have the libraries cached in their browser. Well, it looks like this is no longer a pipe-dream now that Google has announced they are hosting several popular JavaScript libraries.

However, hosting libraries on a common domain isn't the only way to tackle the large download issue. Douglas Crockford has an excellent suggestion to improve library performance through the use of a hash code making it possible for browsers to reuse libraries regardless of the site hosting them. I won't go into the details of the his idea (follow the link for that) but mention that the one major flaw is that browsers must implement this. Even if the browser vendors do add this feature it would be years before it could be used by Web Developers.

This brings us back to the hosted libraries solution. It can be implemented now (not dependent on browser vendors) but comes with the downside that the site hosting the libraries is in complete control of what libraries are available. Google might not be overly evil but it probably won't host just any library. There are some simple solutions to this however.

Instead of Google hosting the libraries, a benevolent consortium backed by industry (Google, Yahoo, Microsoft, etc.) could provide the hosting and provide a very open means to upload any library. This is a bit idealistic and could be subject to abuse, but is probably doable.

The best and most realistic solution, however, is probably to push browser vendors to still adopt the hash attribute. Google has stated it will work with the browser vendors to possibly bundle the libraries with the browser, but this will create an even bigger obstacle to non-approved libraries. I like my web open and full of options and hope the hash solution is considered fully.

Update:
Looks like Google will be providing secure access to the libraries as well. Nice move and something that Yahoo does not provide with YUI.

No comments:

Post a Comment