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

16 April 2011

If you use Google’s CDN, if at all possible, you really want to be spe­cific 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 in­struc­tions 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 Pro­to­type—no more and no less—then the browser is able to cache the library for 1 year.

boom:~$ wget --quiet --save-headers -O - \ | grep ^Cache\-Control
Cache-Control: public, must-revalidate, proxy-revalidate, max-age=3600
boom:~$ wget --quiet --save-headers -O - \ | grep ^Cache\-Control
Cache-Control: public, max-age=31536000