使IE缓存资源,但始终重新验证 [英] Make IE cache the resources but always revalidate

查看:63
本文介绍了使IE缓存资源,但始终重新验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

缓存控制标头 no-cache,must-revalidate,private允许浏览器缓存资源,但使用条件请求强制进行重新验证。

The cache control header "no-cache, must-revalidate, private" allows browsers to cache the resource but forces a revalidate with conditional requests. This works as expected in FF, Safari, and Chrome.

但是,IE7 + 8不会发送条件请求,即 If-Modified-Since是缺少请求标头,因此服务器使用HTTP / 200而不是HTTP / 304进行响应。

However, IE7+8 does not send a conditional request, that is, "If-Modified-Since" is missing in the request header and hence the server responds with HTTP/200 instead of HTTP/304.

以下是完整的服务器响应标头:

Here are the full server response headers:

Last-Modified: Wed, 16 Feb 2011 13:52:26 GMT
Content-type: text/html;charset=utf-8
Content-Length: 10835
Date: Wed, 16 Feb 2011 13:52:26 GMT
Connection: keep-alive
Cache-Control: no-cache, must-revalidate, private

这似乎是IE的错误,但我在网上找不到任何相关内容,因此我想知道是否存在另一个标头是否会使IE表现出异常?

This seems like an IE bug, but I haven't found anything related on the web, so I wonder whether maybe the absence or existence of another header makes IE behave strangely?

关于无缓存和max-age之间的区别的很好的讨论:有什么不同Cache-Control:max-age = 0和no-cache之间有什么联系?

A good discussion of the difference between no-cache and max-age: What's the difference between Cache-Control: max-age=0 and no-cache?

推荐答案

我最终想通了出来。这是一个说明和一个经过测试的解决方案。

I've eventually figured it out. Here is an explanation and a tested solution.

以下站点证实了我的观察: http://blog.httpwatch.com/2008/10/15/two-important-differences-between-firefox -and-ie-caching /

The following site confirms my observation: http://blog.httpwatch.com/2008/10/15/two-important-differences-between-firefox-and-ie-caching/

它表示IE不会使用 no-cache指令在本地存储页面,因此总是发送无条件请求。

It says that IE does not locally store pages with the 'no-cache' directive and hence always sends an unconditional request.

还有一篇MS支持文章- https ://support.microsoft.com/help/234067/ -确认:

There's also a MS support article - https://support.microsoft.com/help/234067/ - which confirms this:

Internet Explorer支持HTTP 1.1缓存控制标头当指定了no-cache值时,将阻止所有特定Web资源的缓存...

"Internet Explorer supports the HTTP 1.1 Cache-Control header, which prevents all caching of a particular Web resource when the no-cache value is specified..."

此行为不是完全错误的-但这不是RFC 2616 (第14.9.1节)。关于 no-cache,它说: ...在未成功验证原始服务器的情况下,缓存不得使用响应来满足后续请求。因此响应可以被缓存,但是必须重新验证它。除IE之外,主要的浏览器都缓存响应并重新验证响应。为防止存储请求,使用了不存储的Cache-Control指令。

This behavior is not entirely wrong -- but it is not what RFC 2616 (sec. 14.9.1) intended. About 'no-cache' it says "... a cache MUST NOT use the response to satisfy a subsequent request without successful revalidation with the origin server." So the response CAN be cached but MUST revalidate it. The major browsers, except for IE, do cache the response and revalidate it. To prevent storing the request, there's the 'no-store' Cache-Control directive.

总而言之,IE将不缓存视为不-

这是解决方案,用于以一致的方式启用对IE和其他浏览器的有条件请求

不使用无缓存,而是将Expires标头设置为过去(或-1,具有相同的效果)。 IE以及其他主要浏览器将随后发送条件请求。 (请注意,您还应该注意IE Vary标头错误,该错误会阻止缓存。)

Don't use no-cache, but instead set the Expires header to the past (or -1, which has the same effect). IE, as well as the other major browsers, will then send conditional requests. (Note, you should also be aware of the IE Vary header bug, which prevents caching.)

这些是关键标头字段:

Last-Modified: Wed, 16 Feb 2011 13:52:26 GMT
Expires: -1
Cache-Control: must-revalidate, private




  • 需要最后修改(或ETag)作为验证器

  • 过期-1表示资源过时,必须重新验证

  • 缓存控件不得包含无缓存或无存储

    这篇关于使IE缓存资源,但始终重新验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆