如何使用HTTP 1.1标头阻止浏览器缓存我的网页? [英] How can I stop browsers caching my web page using HTTP 1.1 headers?
问题描述
虽然我已将 Expires
设置为过去的日期,而 Cache-Control
设置为 no-store,no-cache
,我仍然得到我的一个网页缓存。
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.
以下是发送到网页的HTTP标头浏览器:
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
FF 3.6,Safari和IE 8的行为相同。
Same behavior for FF 3.6, Safari and IE 8.
如何让浏览器停止缓存页面?
How do I get browsers to stop caching the page?
推荐答案
以下标题包含总是对我有用(对于HTTP / 1.1)。你应该不需要Pragma:no-cache。
The following headers have always worked well for me (for HTTP/1.1). You should not need Pragma: no-cache.
Cache-Control: no-cache
Expires: <some date in the past>
Vary: *
尝试将我的Vary值更改为我的示例中的星号。
Try changing your Vary value to the asterisk from my example.
每 http ://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.44 :
Vary字段值*表示缓存无法从请求标头中确定后续请求是否该响应是适当的表示。
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."
这篇关于如何使用HTTP 1.1标头阻止浏览器缓存我的网页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!