如何阻止浏览器使用 HTTP 1.1 标头缓存我的网页?
尽管我已将 Expires
设置为过去的日期,并将 Cache-Control
设置为 no-store, no-cache
,但我仍然得到一个我的网页已缓存。
以下是发送到浏览器的 HTTP 标头:
Date: Tue, 02 Nov 2010 09:13:23 GMT
Server: Apache/2.2.15 (el)
X-Powered-By: PHP/5.2.13
Set-Cookie: PHPSESSID=2luvb7b316lfc8ht570s1l1v84; path=/
Set-Cookie: Newsletter_Counter=17; expires=Wed, 02-Nov-2011 09:13:23 GMT; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 20
Connection: close
Content-Type: text/html; charset=UTF-8
FF 3.6、Safari 和 IE 8 的行为相同。
如何让浏览器停止缓存页面?
Although I have set Expires
to a date in the past, and Cache-Control
to no-store, no-cache
, I still get one of my web pages cached.
Here are the HTTP headers sent to the browser:
Date: Tue, 02 Nov 2010 09:13:23 GMT
Server: Apache/2.2.15 (el)
X-Powered-By: PHP/5.2.13
Set-Cookie: PHPSESSID=2luvb7b316lfc8ht570s1l1v84; path=/
Set-Cookie: Newsletter_Counter=17; expires=Wed, 02-Nov-2011 09:13:23 GMT; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 20
Connection: close
Content-Type: text/html; charset=UTF-8
Same behavior for FF 3.6, Safari and IE 8.
How do I get browsers to stop caching the page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
浏览器自己决定缓存。您可以使用随机 GET 参数来强制浏览器不缓存,例如
Browsers decide caching themselves. You can use a random GET parameter to force browsers not to cache, e.g.
以下标头对我来说一直很有效(对于 HTTP/1.1)。您应该不需要需要Pragma:no-cache。
尝试将我的示例中的 Vary 值更改为星号。
根据 http://www.w3.org/Protocols/rfc2616/ rfc2616-sec14.html#sec14.44:
“Vary 字段值为“*”意味着缓存无法根据后续请求的请求标头确定此响应是否是适当的表示。”
The following headers have always worked well for me (for HTTP/1.1). You should not need Pragma: no-cache.
Try changing your Vary value to the asterisk from my example.
Per http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.44:
"A Vary field value of "*" implies that a cache cannot determine from the request headers of a subsequent request whether this response is the appropriate representation."
使用
缓存控制:无存储
应禁止任何存储:Using
Cache-Control: no-store
should forbid any storage:您当然似乎在做正确的事情(但就像很多人似乎认为发送“Pragma:no-cache”响应标头对浏览器端缓存有一些影响 - 它不应该)。
你的意思是它被缓存了?如果用户单击“后退按钮”并使用 GET 操作检索它,则(通常)不会再次从服务器获取它。
You certainly seem to be doing the right things (but like a lot of people seem to assume that sending a 'Pragma: no-cache' response header has some effect on browser side caching - it should not).
What do you mean its getting cached? It will not (usually) be fetched again from the server if the user clicks on the 'back button' and was retrieved using a GET operation.