META cache
This should be a post about using the html tag META with an equivalent to Expires to define an expiration time. But that makes no sense in most situations! Usually we want to say "check this every day" or "every 5 minutes" and that implies an expiration time relative to last access, something we can't do with META Expires — only absolute expiration times are possible. So it's time to move on.
HTTP 1.1 defines the header Cache-Control to extend the basic mechanism "cache validator / expiration time". There is an alternative to Expires, the max-age directive. The interesting point about max-age is that it sets the expiration time relative to last access.
But no browser tested has seen meta Cache-Control as a true equivalent of http Cache-Control, although most are near. With max-age set to a positive value:
- Explorer ignores meta Cache-Control, or max-age in it.
- Mozillas check with outworld after max-age period, but also make one check for each two requests while cache is fresh (should use cache).
- Opera almost did it: page is checked after serving from cache for the max-age period and then other period starts… if the page was modified; for not modified items Opera checks each new request until refresh.
Was expecting something better… more tests around META cache:
- Cache-Control with max-age=0: ignored by Explorer and respected by everyone else (no way to test IE7 release candidate: XP++ only).
- Expires with future date: working with Opera and Explorer (using cache before expiration time and checking every request after time). Mozillas "check even requests" before timeout and check every request after.
- Expires with past date: works for all, Explorer since 01 Jan 1980!
- Pragma with no-cache: works for all.
Humm, seems time to move back… to Expires with past date, or Pragma with no-cache. Those two are used to keep the page fresh, requesting a check for each revisit. It is good to be checked, but there is a drawback: latency [and some bandwidth consumption, a 304 can use hundreds of bytes].
But not even the old Pragma can be trusted. Proxies do not read html meta tags; if a proxy is in the way chances are that he keeps the page and returns a hit next time page is requested:
HTTP/1.1 200 OK
Last-Modified: Sun, 17 Sep 2006 01:45:28 GMT
ETag: "16217-6a7-697fb47b"
X-Cache: MISS from localhost
GET /cache/static3/pragma.html HTTP/1.1
If-Modified-Since: Sun, 17 Sep 2006 01:45:28 GMT
If-None-Match: "16217-6a7-697fb47b"
HTTP/1.1 304 Not Modified
Last-Modified: Sun, 17 Sep 2006 01:45:28 GMT
ETag: "16217-6a7-697fb47b"
X-Cache: HIT from localhost
This is not a big deal for sparsely visited pages, they are soon overwritten by more hitted ones in proxy cache. For people that has some server space provided by ISP, and can't run scripts or set expiration with http, "meta Pragma no-cache" still is the way to keep pages fresh. Other items like images can't be expired this way, so here is the tip: never change other items without changing their name. Alter the links in html pages, in next visit the new links will be detected and the changed items will be requested.

2 Comments:
definitively, IE6 does not recognize meta Cache-Control
one thing to note about "Pragma: no-cache" response [specified by the server]: this is not standard and does not work with IE6 when included in http headers. On the other hand, works well for [all tested] browsers in meta tags...
Post a Comment
<< Home