To indicate the need to check the validity of the saved cache before each subsequent request, we can use Cache-Control: no-cache
with the validator (ETag
or Date
+Last-Modified
) in the server response.
A more compatible way to revalidate, if I understand correctly, is to use max-age=0, must-revalidate
instead of no-cache
. A wide range of historical reasons to use the second option has been discussed in the very helpful thread What's the difference between Cache-Control: max-age=0 and no-cache?
The value max-age=0, must-revalidate
(with private
or public
) is the most popular among no-cache
alternatives (according to usage statistics from Webtechsurvey).
Among the alternatives, there is a slightly less popular option no-cache, must-revalidate, max-age=0
, which I do not understand. It's probably aimed at supporting HTTP/1.0 and other things that don't recognize no-cache, however I understand that this causes problems in some older browsers that changed the no-cache
behavior as mentioned in the discussion at the link.
The problem is that unlike no-cache
, if there is no server response, using must-revalidate
will not allow the cache to be used and should show a 504 error. If we do not use must-revalidate, this can lead to a false positive hash, which is mentioned all in the same topic.
Question: how to create a max-age:0
compatibility level check with a mandatory cache check and a mandatory download of a new version (without heuristic risks), if the server is in order, and if the server does not respond, then issue the cache? Is there an ideal solution or should there be compromises?
p.s. Of course, this makes the cache potentially out of date in conditions where we allegedly require it to be perfectly up to date and do this at the expense of additional HTTP requests. However, with some conscious risk approach, showing cache may be a better SEO strategy than showing an error.