如何阻止浏览器使用 HTTP 1.1 标头缓存我的网页?

发布于 2024-09-30 05:36:46 字数 719 浏览 1 评论 0原文

尽管我已将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

无声无音无过去 2024-10-07 05:36:46

浏览器自己决定缓存。您可以使用随机 GET 参数来强制浏览器不缓存,例如

http://www.foo.com/yourfile.zip?id=1234

Browsers decide caching themselves. You can use a random GET parameter to force browsers not to cache, e.g.

http://www.foo.com/yourfile.zip?id=1234
萌梦深 2024-10-07 05:36:46

以下标头对我来说一直很有效(对于 HTTP/1.1)。您应该不需要需要Pragma:no-cache。

Cache-Control: no-cache
Expires: <some date in the past>
Vary: *

尝试将我的示例中的 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.

Cache-Control: no-cache
Expires: <some date in the past>
Vary: *

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

人间☆小暴躁 2024-10-07 05:36:46

使用 缓存控制:无存储 应禁止任何存储:

无商店
[…]如果在响应中发送,缓存不得存储该响应或引发该响应的请求的任何部分。该指令适用于非共享和共享缓存。 [...]

Using Cache-Control: no-store should forbid any storage:

no-store
[…] If sent in a response, a cache MUST NOT store any part of either this response or the request that elicited it. This directive applies to both non- shared and shared caches. […]

不弃不离 2024-10-07 05:36:46

您当然似乎在做正确的事情(但就像很多人似乎认为发送“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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文