Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
629 views
in Technique[技术] by (71.8m points)

caching - HTTP Cache - check with the server, always sending 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).

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...