5

When caching a HTML page with must-revalidate, this means that browser must check for any update defined by Last-Modified or Etag. However, the problem is that before max-age, browser will not make any connection with the website to read HTTP headers (to analyze Last-Modified and Etag)?

How to force the browser to make a brief connection to read (at least) HTTP readers before loading the page from cache?

I do not understand the usage of must-revalidate! Doesn't it its responsibility to check for updates before max-age? because after reaching max-age, browser will read from the website and never use local cache.

Googlebot
  • 15,159
  • 44
  • 133
  • 229

1 Answers1

10

Yes, your understanding of must-revalidate is wrong: it says that the cache may not serve this content when it is stale (i.e. "expired"), but must revalidate before that. Yes, caches (and browsers) can in theory be set to serve pages even if they are stale, though the standard says they should warn the user if they do this.

To force the browser to recheck your page with the server, the simplest solution is to add max-age=0 to the Cache-Control header. This will let your browser keep a copy of the page in its cache, but compare it with the server's version by sending the contents of Last-Modified or ETag, as you wanted.

It used to be that you could add no-cache instead, but as users have been expecting this to behave as no-store, browsers are gradually treating them the same.

Check the HTTP/1.1 RFC, section 14.9 for more information on the headers.

Ben Deutsch
  • 688
  • 1
  • 5
  • 11
  • 1
    very useful infromation and practical guide, but I did not understand one thing. You said "the cache may NOT serve this content when it is expired, but must revalidate before that". In any case, even without `must-revalidate`, cache will NOT be served when expired. – Googlebot Apr 06 '12 at 13:53
  • 2
    If you reread the end of 14.9.3 in the RFC above, it mentions that not only can caches be configured to serve stale responses, clients (browsers) could use `max-stale` to indicate that a stale response is fine. It also mentions that a `Warning` header must be attached, though. – Ben Deutsch Apr 06 '12 at 17:25