HAYCORN — 27 May 2008

JavaScript frameworks hosted by Google

For a little while the YUI has been hosted by Yahoo; now Google is doing the same for jQuery, Prototype et al. There’s some documentation available but essentially you do e.g.:

<script
type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/prototype.js">

(You can select specific major/minor versions via different URLs, though this places some limitations on the expiry headers that get sent back.)

Google recommends that you load the frameworks via google.load(). What is the advantage of doing this? It seems to do nothing other than add overhead unless there are complicated dependencies.

The headers that come back are

HTTP/1.0 200 OK
Last-Modified: Sat, 24 May 2008 00:39:29 GMT
Content-Type: application/x-javascript
Expires: Wed, 27 May 2009 20:51:04 GMT
Date: Tue, 27 May 2008 20:51:04 GMT
Cache-Control: public, max-age=31536000
Content-Encoding: gzip
Server: GFE/1.3
Connection: Close

which seem pretty sensible. (Curiously, you only get a gzip response with a Accept-Encoding that includes gzip and a User-Agent Google recognises, like that of Firefox. wget --header="Accept-Encoding: gzip,compress" won’t do it.)

I don’t know of any privacy or service guarantees. However, as Dion Almaer points out, they’re served from a ajax.googleapis.com, not google.com, so users’ google.com cookies aren’t available for tracking. As of now the service doesn’t set any either.

I’ve done a few quick tests, and serving prototype.js (30k, compressed) from Google to the UK and US is 4-5 times as fast as prototype.js from beebo.org (in Paris). For Australia, though, it’s only slightly faster.