HAYCORN — 16 April 2011

JavaScript CDNs: for effective caching be specific about the version you want

If you use Google’s CDN, if at all possible, you really want to be specific about the version of the library you want. Otherwise, if you say you want 1.7.x, the library will need to be sent to the browser with instructions to check back every so often to see if a newer release in the 1.7 series is available, which in Google’s case is just 1 hour. On the other hand, if you are able to specify that you want Prototype 1.7.0.0—no more and no less—then the browser is able to cache the library for 1 year.

boom:~$ wget --quiet --save-headers -O - \
http://ajax.googleapis.com/ajax/libs/prototype/1.7/prototype.js | grep ^Cache\-Control
Cache-Control: public, must-revalidate, proxy-revalidate, max-age=3600
boom:~$ wget --quiet --save-headers -O - \
http://ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js | grep ^Cache\-Control
Cache-Control: public, max-age=31536000