这个请求,可以看到response中既没有cache-control也没有expires,应该没有命中强缓存,但是我点击f5刷新后,返回200 from cache。请问这是如何实现的?
设置etag和lastModified不是都应该命中协商缓存 返回304吗?
这个请求,可以看到response中既没有cache-control也没有expires,应该没有命中强缓存,但是我点击f5刷新后,返回200 from cache。请问这是如何实现的?
设置etag和lastModified不是都应该命中协商缓存 返回304吗?
属于强缓存 具体标准相关信息如下
https://developer.mozilla.org...
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.
https://datatracker.ietf.org/...
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%.
因为Response Header 存在 Date、Last-Modified
浏览器使用LM factor 算法在没有 Cache-Control 以及 Expires 的时候,用来计算应该强制缓存多长时间所以状态码返回还是200 不是 304
8 回答4.7k 阅读✓ 已解决
6 回答3.4k 阅读✓ 已解决
6 回答2.3k 阅读
5 回答6.3k 阅读✓ 已解决
3 回答2.4k 阅读✓ 已解决
3 回答2.1k 阅读✓ 已解决
3 回答2.5k 阅读✓ 已解决
如果什么缓存策略都没设置,浏览器会采用一个启发式的算法,通常会取响应头中的 Date 减去 Last-Modified 值的 10% 作为缓存时间。