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:
Request | Response cached for |
---|---|
/1.3.2/jquery.min.js | one year |
/1.3/jquery.min.js | no caching |
/1/jquery.min.js | one 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.