HTTP Cache Control max-age, must-revalidate

后端 未结 3 713
青春惊慌失措
青春惊慌失措 2020-11-29 21:16

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, wit

相关标签:
3条回答
  • 2020-11-29 21:51

    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).

    0 讨论(0)
  • 2020-11-29 21:56

    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.

    0 讨论(0)
  • 2020-11-29 22:02

    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.

    0 讨论(0)
提交回复
热议问题