HTTP Cache Control max-age, must-revalidate

HttpHttp HeadersCache Control

Http Problem Overview


I have a couple of queries related to Cache-Control.

If I specify Cache-Control max-age=3600, must-revalidate for a static html/js/images/css file, with Last Modified Header defined in HTTP header:

  1. Does browser/proxy cache(like Squid/Akamai) go all the way to origin server to validate before max-age expires? Or will it serve content from cache till max-age expires?
  2. After max-age expiry (that is expiry from cache), is there a If-Modified-Since check or is content re-downloaded from origin server w/o If-Modified-Since check?

Http Solutions


Solution 1 - Http

a) If the server includes this header:

Cache-Control "max-age=3600, must-revalidate"

it is telling both client caches and proxy caches that once the content is stale (older than 3600 seconds) they must revalidate at the origin server before they can serve the content. This should be the default behavior of caching systems, but the must-revalidate directive makes this requirement unambiguous.

b) The client should revalidate. It might revalidate using the If-Match or If-None-Match headers with an ETag, or it might use the If-Modified-Since or If-Unmodified-Since headers with a date.

Solution 2 - Http

a. Look at the ‘Stats’ tab on this page and see what happens.

b. After expiration the browser will check at the server if the file is updated. If not, the server will respond with a 304 Not Modified header and nothing is downloaded.

You can check this behaviour yourself by looking at the ‘Net’ panel in Firebug or similar tools. Just re-enter the URL in the address bar and compare the number of HTTP requests with the number of requests when your cache is empty.

Solution 3 - Http

The given answers are incorrect, at least for web browsers in 2019.

"After expiration the browser will check at the server if the file is updated" <- not true

I have a static file served with "Cache-Control: public,must-revalidate,max-age=864000" and both Chrome and Firefox do a request every time (and get a 304 Not Modified back every time).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnybView Question on Stackoverflow
Solution 1 - Httpjames.garrissView Answer on Stackoverflow
Solution 2 - HttpMarcel KorpelView Answer on Stackoverflow
Solution 3 - Httpmhenry1384View Answer on Stackoverflow