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.
Yes, your understanding of
must-revalidateis 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=0to theCache-Controlheader. 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 ofLast-ModifiedorETag, as you wanted.It used to be that you could add
no-cacheinstead, but as users have been expecting this to behave asno-store, browsers are gradually treating them the same.Check the HTTP/1.1 RFC, section 14.9 for more information on the headers.