请问没有设置cache-control和expires的情况下,这个请求是如何实现200 from cache的?

这个请求,可以看到response中既没有cache-control也没有expires,应该没有命中强缓存,但是我点击f5刷新后,返回200 from cache。请问这是如何实现的?
设置etag和lastModified不是都应该命中协商缓存 返回304吗?
图片描述

阅读 10.7k
5 个回答

如果什么缓存策略都没设置,浏览器会采用一个启发式的算法,通常会取响应头中的 Date 减去 Last-Modified 值的 10% 作为缓存时间。

如果没有Cache-ContorlExpires的 header,但有Last-Modified,很多浏览器会这样计算

(current time - last modified time) / 10 

RFC7234

chrome浏览器自带文件内存缓存,你可以使用firefox浏览器看看

属于强缓存 具体标准相关信息如下

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

推荐问题
宣传栏