最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

browser - HTTP caching of transitive resources using IF-Modified-Since - Stack Overflow

programmeradmin2浏览0评论

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

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

Share Improve this question edited Mar 14 at 10:53 Cheetah asked Mar 14 at 10:40 CheetahCheetah 14.5k33 gold badges119 silver badges207 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

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.

发布评论

评论列表(0)

  1. 暂无评论