HTTP缓存 - 检查服务器,始终发送If-Modified-Since [英] HTTP Cache - check with the server, always sending If-Modified-Since

查看:281
本文介绍了HTTP缓存 - 检查服务器,始终发送If-Modified-Since的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户生成的资源,因此在不可预测的时间进行更改(例如,用户上传word文档的新版本)。我希望浏览器缓存此资源并在每个请求上使用服务器验证其缓存(即始终发送If-Modified-Since标头)。

I have a resource which is user generated and therefore changes at an unpredictable time (example, a user uploads a new version of a word document). I would like browsers to cache this resource and validate its cache with the server on each request (i.e. always send the If-Modified-Since header).

从测试中,我我发现当我在响应头中使用Cache-Control:no-cache时,Firefox会正确处理这个问题。但是,Internet Explorer 7未在其请求标头中发送If-Modified-Since。

From testing, I've found that Firefox handles this appropriately when I use "Cache-Control: no-cache" in the response header. However, Internet Explorer 7 is not sending "If-Modified-Since" in its request header.

Cache-Control:no-cache是否实现了我在一开始?如果没有,我能做些什么来实现我在浏览器中描述的内容吗?

Does "Cache-Control: no-cache" achieve what I described at the beginning? If not, is there anything I can do differently to achieve what I've described across browsers?

谢谢。

推荐答案

根据Microsoft( http://support.microsoft。 com / kb / 234067 ),您需要将Expires标头设置为-1才能在Internet Explorer中正常工作。

According to Microsoft (http://support.microsoft.com/kb/234067), you need to set the Expires header for -1 for this to work properly in Internet Explorer.

从页面:


在许多情况下,Web服务器在
包含信息的服务器上有一个或
更易变的页面,这是主题
立即更改。这些页面
应由服务器标记为
,对于Expires
标头,值为-1。在
用户的未来请求中,Internet Explorer通常
通过条件
If-Modified-Since请求联系Web服务器以更新
该页面。

In many cases, Web servers have one or more volatile pages on a server that contain information, which is subject to change immediately. These pages should be so marked by the server with a value of "-1" for the Expires header. On future requests by the user, Internet Explorer usually contacts the Web server for updates to that page via a conditional If-Modified-Since request.

我认为关键是如果IE有一个到期日期,它认为没有理由询问你资源是否已被修改,因为它的缓存副本应该足够好。

I think the point is that if IE has an expiration date, it sees no reason to ask you if the resource has been modified, since its cached copy should be "good enough".

该页面还说IE支持Cache-control:no-cache,但不推荐使用。所以它听起来应该可行,但无论如何都要尝试Expires。

The page does also say that IE supports Cache-control: no-cache, though it isn't recommended. So it sounds like it should work, but try the Expires thing anyway.

此外,其他谷歌搜索告诉我浏览器应该发送If-Modified-Since一般来说,所以也许这就是Firefox的工作原理。尝试删除Cache-Control:no-cache以查看Firefox是否仍能正常运行。

Also, other googling tells me that browsers are expected to send If-Modified-Since in general, so maybe that's why Firefox works. Try removing Cache-Control: no-cache to see if Firefox still behaves correctly.

这篇关于HTTP缓存 - 检查服务器,始终发送If-Modified-Since的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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