internet-explorer - 浏览器使用什么启发式方法来缓存未明确设置为可缓存的资源?

标签 internet-explorer google-chrome firefox safari browser-cache

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 .

建议

  • 仅使用 HTTP header 来控制浏览器缓存 .如果您决定反对这一点,请注意 IE 仅识别在 HTML 中设置的两个缓存控制指令:
    <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标题 .在现代浏览器中 ExpiresCache-Control 取代. Expires: 0Pragma: 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如果没有,它可以避免发出完整的请求。
  • 请注意,某些浏览器刚刚损坏,需要破解 . IE 8 can have issues downloading files which it has been told not to cache .

  • 浏览器缓存算法
  • Chrome 49.0.2606.2 HttpResponseHeaders::GetFreshnessLifetimes()
  • Firefox HTTP Caching FAQ , Firefox 38 ESR nsHttpResponseHead::ComputeFreshnessLifetime() .
  • Internet Explorer (6+?) , HTTPS caching in IE 8+ , Internet Explorer 9+ , Internet Explorer 9+ .
  • Webkit (Safari) computeFreshnessLifetimeForHTTPFamily()

  • 也可以看看
  • Google's browser caching recommendations .
  • 关于internet-explorer - 浏览器使用什么启发式方法来缓存未明确设置为可缓存的资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14345898/

    相关文章:

    css - 为什么这个 html/css 在 ie 中不起作用?

    html - 永久更改 HTML 元素

    css - 选择必须在粘住时双击 chrome

    css - -webkit-box-reflect 在 firefox 和 IE 中 - CSS

    html - IE 无法显示部分 Wordpress 网站

    javascript - 在图像标签 IE11 上添加自定义属性时无法发布表单?

    safari - 我已经在 Chrome 中测试过了,还需要在 Safari 中测试吗?

    android - 为 Google Cloud Endpoint API 设置 TLS 代理

    python :如何打开火狐(OS X)

    javascript - IE11 不能很好地处理 Blob 构造函数和 javascript 数组