Enhance caching detection
Hi,
I've been auditing nasty cache problems recently, and I've learnt some vicious things about caching headers:
-
If a
Dateheader is provided by the server, the browser uses it to calculate the expire date. TheDateheader should always respond with the hour of the request, but some badly configured proxies don't reset it and keep the date when they last refreshed their cache. So inside Phantomas, the TTL should be calculated using this header instead ofnew Date()when it's available. -
If the server provides an
Ageheader, the browser also uses it to calculate the expiration date :TTL = max-age - age. -
If there is a
Varyheader and its is notAccept-Encoding,Host,User-Agentor any combination of these 3, than Internet Explorer will ignore the cache duration. Have a look here. See the update note at the end of the article? I've tested IE10 and IE11 and they have the same behavior as IE9.
The third point probably fits into the cachingDisabled metric, rather than creating a new metric.
Point 1: makes sense.
As for the second point: I'd rather not consider Age response header. phantomas reports the caching policies from the "server perspective". Including Age in the equation would make these metrics not quite deterministic (i.e. depending on the time we hit the caching layer).
Point 3: definitely worth reporting (and yay for Internet Explorer "awesome" features :) )
Thanks, @gmetais! Have a nice weekend :)