Swati Walvekar
Swati Walvekar

Reputation: 1

chrome browser shows 200(from disk cache) only if etag and last-modified-date both are used

why does chrome browser show 200(from disk cache) only if etag and last-modified-date both are used and not if only etag response header is set ? Note : etag generation is done correctly . In my case I needed etag and last-modified date was not really needed

Upvotes: 0

Views: 3136

Answers (2)

孟世博
孟世博

Reputation: 1

TL;DR

New MDN link: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#up-to-date_contents_always

For content that’s generated dynamically, or that’s static but updated often, you want a user to always receive the most up-to-date version.

If you don't add a Cache-Control header because the response is not intended to be cached, that could cause an unexpected result. Cache storage is allowed to cache it heuristically — so if you have any requirements on caching, you should always indicate them explicitly, in the Cache-Control header.

Adding no-cache to the response causes revalidation to the server, so you can serve a fresh response every time — or if the client already has a new one, just respond 304 Not Modified.

Upvotes: 0

Mark Lin
Mark Lin

Reputation: 21

TL;DR

  • Because most of the browsers will assign a heuristic expiration time when there is no Cache-Control nor explicit expiration times based on the Last-Modified time [1].

  • Could add Cache-Control: must-revalidate header into the response for cache control [2].


[1] https://datatracker.ietf.org/doc/html/rfc7234#section-4.2.2

If the response has a Last-Modified header field (Section 2.2 of
[RFC7232]), caches are encouraged to use a heuristic expiration value that is no more than some fraction of the interval since that time.
A typical setting of this fraction might be 10%.

[2] https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#revalidation_and_reloading

Upvotes: 1

Related Questions