当用户单击后退按钮时,如何防止缓存页面被提供?

Dar*_*ong 2 html browser caching

我知道这个问题之前已被多次询问过,但是发布的解决方案对我不起作用.

我在<head>标签中添加了以下内容,但无济于事:

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
Run Code Online (Sandbox Code Playgroud)

我也看到一些关于onunload浏览器中的属性和bfcache的提及,所以我将其添加到<body>标签中,也无济于事.

我服务器的响应头包含:

Cache-Control   max-age=0, private, must-revalidate
Run Code Online (Sandbox Code Playgroud)

如果有人能指出我正确的方向,我会感激不尽 - 我做错了什么?

Dar*_*ong 6

回答我自己的问题.事实证明,设置以下响应标头(而不是META标签)对我有用:

Cache-Control private, no-store, max-age=0, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma no-cache
Expires Fri, 01 Jan 1990 00:00:00 GMT
Run Code Online (Sandbox Code Playgroud)

如果您像我一样在Rails中工作,可以通过将以下内容放入ApplicationController before_filter回调中来轻松完成:

response.headers["Cache-Control"] = "private, no-store, max-age=0, no-cache, must-revalidate, post-check=0, pre-check=0"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
Run Code Online (Sandbox Code Playgroud)