RSS Feeds

HTTP Caching Revisited

I find the issues around of Web performance very interesting.  I’ve researched pretty comprehensively and written a few articles in this area. I also routinely use various web tools to instrument sites that I visit to see how they perform, and quite frankly a lot are middling to terrible in performance terms.  An example is the MoneyCorp GPS application that I discussed in a previous article, I have subsequently found worse sites (e.g. the RadioTimes TV website which scores 18-25 depending on page), though in these cases the main effect is a case of loading slowly, rather than failing to load at all as in the case of GPS.

However, what I have noticed with some sites is that they seemed to perform reasonably well from a user-perspective even though Google PageSpeed marks them down for not specifying caching parameters.  The relevant Google recommendations on “Leverage browser caching” describe the use of the HTTP headers Expires, Cache-Control max-age, Last-Modified and Etag for resources that you wish cached by the client browser, as I have discussed perviously.  This guidance really only relates to the mandatory rules for browser caching detailed in RFC 2616 (HTTP/1.1) in section 13.2.  However, in addition to these mandatory rules, most browsers also implement an advisory rule that is discussed in section 13.2.4, and which is based on any Last-Modified header if provided.  If present, then life of the cached resource is the age at download (the delta of Date and Last-Modified values) divided by a factor X.  The factor “X = 10” is suggested in the RFC and this is what IE, Firefox and Chrome use.  So by example, if a resource is 10 weeks old at download, then its cached copy will be treated as valid for one week from download.

Apache and IIS both supply Date and Last-Modified headers by default for file-based resources, hence despite the general “best practice” advice on specifying these headers, such file-based resources will frequently be cached.

Conversely, script-based resources will not be unless the code explicitly emits the correct headers.