Using Google Gears on a Weblog

My buddy Niall Kennedy has added Google Gears support to his weblog. While most folks think of Google Gears as just a plugin that helps you go offline, it also includes interesting tools that can help with web site performance, such as a local server that can serve resources and a local database for storing client-side data. Niall specifically used Gears to improve the performance of his blog by having all the images and resources of his blog get cached into the Gears local server. The end result of this is that when users hit his site in the future, images and other ancillary resources are served from Gears rather than his remote web site, improving the load time of his page.

A similar effect can be achieved by simply turning on HTTP/1.1 caching for your images and scripts. However, this caching is on a file-by-file level. The nice thing about Gears is you can bundle an entire set of resources at once, versioning them. You do this with a simple manifest file that you put on your web server. Here is Niall's:
If Niall wants to refresh all of these resources, he can just change the "version" number; Gears will then refresh all of the resources when this happens.

Read more info on manifest files here; Dion Almaer has also written a tool that can help generate them for you.

Note that the manifest file isn't enough; you will need to create a bit of JavaScript that loads the manifest file for Gears. It would be cool if Gears would do this automatically, perhaps when the file has a well-known name on the root, such as /x-gears-manifest.json or something; note that this isn't on the roadmap right now -- it's just a random idea from me.

Niall also tied in a bit of reporting so he could track how many of his visitors are using Google Gears using a clever trick. In his JavaScript he put some Urchin tracking code to see how many folks grabbed the Gears manifest file (Niall told me it was ok to share this):
Now if Gears initializes and is present, we reached the urchinTracker() call and the fact that Gears was initialized is registered with Urchin. BTW, if you don't know what Urchin is its a tool that you can plug into your web pages to get analytics and find out what pages are being accessed and how.


focusfriend said…
Why all this hassle? Just put Google's gadget open proxy in front of all your static content: + your URL

Your buddy Nial mentioned this already several months ago, see the "Open caching proxy" section at:

Cheers, Ivo
burtonator said…
You can do all of this with HTTP caching.

Just tell Apache to add cache headers for all files in a directory.

Then version the directory so that if want to change everything you just use a different versioned path when you serve your HTML.


Popular Posts