Paul Irish

Making the www great

Caching and Google's Ajax Libraries API -- Cache Your jQuery

Leveraging Google’s free hosting of common javascript libraries seems to be getting more popular. While you should be serving all javascript concatenated and minified together, the free hosting is nice for quick jobs or more minimal projects.

The versioning system they devised is a very clever way to always serve you the most up-to-date script. For example, you request version 2 of SWFObject and it’ll currently deliver 2.2, but in the future you’ll always get the most recent 2.x release.

I did a bit of research on how they handle these cases, and since these facts aren’t elsewhere, they needed a home. :)

The current caching rules are as follows:

RequestResponse cached for
/1.3.2/jquery.min.jsone year
/1.3/jquery.min.jsno caching
/1/jquery.min.jsone hour

jQuery URLs used only for illustration purposes. It’s the same case with all scripts’ minor/major versions Minified and unminified files are treated the same

Previous to now, using the google.load('jquery','1.2.6') technique was the only way to ensure the script stayed considerably cached. Direct path-based access scripts were only cached for one day. But no worries, because all is better now.

2010.08.25 - Updated caching times. How odd..

Comments