How do I cache an HTML page with required confirmation?

When caching an HTML page from, must-revalidate

this means that the browser should check for any update, defined Last-Modified

or Etag

. However, the problem is that until the max-age

browser will contact the website to read the HTTP headers (to parse Last-Modified

and Etag

)?

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

I don't understand the use must-revalidate

! Does he not respond to updates before max-age

? because after reaching the max-age

browser will read from the site and never use the local cache.

+3


source to share


1 answer


Yes, your understanding must-revalidate

is wrong: it says that the cache may not serve this content when it is out of date (ie "expired"), but must check again before doing so. Yes, caches (and browsers) could theoretically be configured to serve pages even if they are outdated, although the standard says they must warn the user if they do.

To force the browser to recheck your page with the server, the simplest solution is to add max-age=0

to the header Cache-Control

. This will allow your browser to keep a copy of the page in the cache, but compare it to the server version by sending the content Last-Modified

or ETag

whatever you wanted.



There used to be something you could add no-cache

instead, but since users expected it to behave like no-store

, browsers will gradually treat them the same way.

For more information on headers check the HTTP / 1.1 RFC section 14.9 .

+8


source







All Articles