13.2.2 Heuristic Expiration
Since origin servers do not always provide explicit expiration times, HTTP caches typically assign heuristic expiration times, employing algorithms that use other header values (such as the Last-Modified time) to estimate a plausible expiration time. The HTTP/1.1 specification does not provide specific algorithms, but does impose worst-case constraints on their results. Since heuristic expiration times might compromise semantic transparency, they ought to used cautiously, and we encourage origin servers to provide explicit expiration times as much as possible. HTTP/1.1 RFC 2616
浏览器使用什么算法来估计合理的到期时间?
理想的答案将涵盖所有主要浏览器,并提供来自源代码或官方博客文章的证据。
最佳答案
让我们假设我们感兴趣的所有浏览器都是 Internet Explorer 8 或更新版本(例如 IE5 有一些带有缓存 header 的可怕行为)。
只有一种基于标准的缓存控制方式(在 HTTP/1.1 中引入) - Cache-Control
HTTP header .
至少自 1996 年以来,IE 一直在使用选择退出策略来缓存 HTTPS 内容。
似乎自推出以来,Chrome 已经选择退出 HTTPS(即除非被告知否则它将缓存它)。 2011 年,Firefox 4(但不是 Safari)切换到选择退出缓存 HTTPS 内容。 Source .
建议
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
并且似乎只有前者在 HTTPS 场景中有用。此外,可以有 problems when trying to use
Pragma
in IE .最后,Chrome ignores cache directives in meta tags进一步降低它们的用处。 Expires
标题 .在现代浏览器中 Expires
被 Cache-Control
取代. Expires: 0
和 Pragma: no-cache
是技术上无效的响应 header 。是的,它们从一开始就存在,但并非所有现代浏览器(例如 Chrome)都使用它们,并且它们已被 Cache-Control
取代。 . Vary
标题是一个雷区 . How Vary
behaves in older IEs . How Vary
behaves with XHR .找出细节作为练习留给读者 - 并留下印象最好为不同的内容使用不同的 URL... ETags
允许浏览器发出条件请求 .Etags allow a browser to do a lightweight check to see if the content has changed如果没有,它可以避免发出完整的请求。
浏览器缓存算法
HttpResponseHeaders::GetFreshnessLifetimes()
nsHttpResponseHead::ComputeFreshnessLifetime()
. computeFreshnessLifetimeForHTTPFamily()
也可以看看
关于internet-explorer - 浏览器使用什么启发式方法来缓存未明确设置为可缓存的资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14345898/