我正在阅读 this great article关于缓存,那里有以下内容:
Validators are very important; if one isn’t present, and there isn’t any freshness information (Expires or Cache-Control) available, caches will not store a representation at all.
The most common validator is the time that the document last changed, as communicated in Last-Modified header. When a cache has a representation stored that includes a Last-Modified header, it can use it to ask the server if the representation has changed since the last time it was seen, with an If-Modified-Since request.
所以,我想知道即使我指定了 Cache-Control: max-age=3600
,浏览器是否会继续发送资源请求(例如 HEAD)?如果没有,那么这个标题的意义何在?是否在 max-age
时间过去后使用?
最佳答案
Cache-Control: max-age=3600
header 表示浏览器会将响应缓存最多 3600 秒。在该时间过去之后,它可能不再提供响应,除非首先确认它仍然是新鲜的。
为此,浏览器可以:
- 使用普通的
GET
请求获取完整资源(再次传输整个响应主体) - 或者根据 ETag (
If-None-Match
) 或 Last-Modified header (If -Modified-Since
),即客户端仅在实际发生更改时才获取响应主体。这当然只有在原始响应中存在验证器时才有可能。
简而言之:同时使用 max-age
和缓存验证器的原因是首先将响应缓存一段时间,然后执行节省带宽的重新验证确认资源的新鲜度。
关于javascript - 即使使用 `Cache-Control: max-age`,浏览器是否继续发送资源请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40342069/