Given:
index.html
main.js
data.json
The initial requests for these files all return the same Last-Modified
header value, but no Cache-Control
header.
A subsequent request is made...
The request to index.html
returns a 304 Not Modified
. This is expected as the If-Modified-Since
header is sent on the request. Nothing strange here.
However, no request is sent to the server for main.js
or any of the resources it fetches (data.json
), they are all served from the local cache.
By inference, it would appear that the browser assumes that if the index.html
is not modified, then neither is main.js
and neither is any of the resources that main.js
fetches. Seems odd to me.
Is this behaviour documented anywhere? Am I missing some headers (there weren't any other cache related ones in the responses that I could see.) I am expecting a request to be made to the server for each of the resources (and potentially a 304 back if they haven't changed)
Chrome v132
If you want a request to be made with each fetch you need to add an explicit Cache-Control: no-cache
header to the response. Otherwise, the browser is free to make its own heuristic caching decisions.
Since origin servers do not always provide explicit expiration times, a cache MAY assign a heuristic expiration time when an explicit time is not specified, employing algorithms that use other field values (such as the Last-Modified time) to estimate a plausible expiration time.