HTTP Cache - check with the server, always sending

2019-01-27 00:23发布

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).

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.

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?

Thanks.

标签: http caching
1条回答
SAY GOODBYE
2楼-- · 2019-01-27 00:57

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.

From the page:

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.

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".

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.

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.

查看更多
登录 后发表回答