我们的调查表明,并非所有浏览器都以统一的方式尊重HTTP缓存指令。
出于安全原因,我们不希望应用程序中的某些页面被web浏览器缓存。这必须至少适用于以下浏览器:
Internet Explorer 6+Firefox 1.5+Safari 3+歌剧9+铬
我们的要求来自安全测试。从我们的网站注销后,您可以按后退按钮并查看缓存的页面。
我们的调查表明,并非所有浏览器都以统一的方式尊重HTTP缓存指令。
出于安全原因,我们不希望应用程序中的某些页面被web浏览器缓存。这必须至少适用于以下浏览器:
Internet Explorer 6+Firefox 1.5+Safari 3+歌剧9+铬
我们的要求来自安全测试。从我们的网站注销后,您可以按后退按钮并查看缓存的页面。
当前回答
通过设置Pragma:无缓存
其他回答
不确定我的答案听起来是否简单和愚蠢,也许你早就知道了,但由于阻止某人使用浏览器后退按钮查看历史页面是你的目标之一,你可以使用:
window.location.replace(“https://www.example.com/page-not-to-be-viewed-in-browser-history-back-button.html");
当然,这可能不可能在整个网站上实现,但至少对于一些关键页面,您可以做到这一点。希望这有帮助。
我在<head><meta>元素方面运气不佳。直接(在HTML文档之外)添加与HTTP缓存相关的参数确实对我有用。
Python中使用web.py-web.header调用的示例代码如下。我有目的地编辑了我个人无关的实用程序代码。
import web import sys import PERSONAL-UTILITIES myname = "main.py" urls = ( '/', 'main_class' ) main = web.application(urls, globals()) render = web.template.render("templates/", base="layout", cache=False) class main_class(object): def GET(self): web.header("Cache-control","no-cache, no-store, must-revalidate") web.header("Pragma", "no-cache") web.header("Expires", "0") return render.main_form() def POST(self): msg = "POSTed:" form = web.input(function = None) web.header("Cache-control","no-cache, no-store, must-revalidate") web.header("Pragma", "no-cache") web.header("Expires", "0") return render.index_laid_out(greeting = msg + form.function) if __name__ == "__main__": nargs = len(sys.argv) # Ensure that there are enough arguments after python program name if nargs != 2: LOG-AND-DIE("%s: Command line error, nargs=%s, should be 2", myname, nargs) # Make sure that the TCP port number is numeric try: tcp_port = int(sys.argv[1]) except Exception as e: LOG-AND-DIE ("%s: tcp_port = int(%s) failed (not an integer)", myname, sys.argv[1]) # All is well! JUST-LOG("%s: Running on port %d", myname, tcp_port) web.httpserver.runsimple(main.wsgifunc(), ("localhost", tcp_port)) main.run()
IE6中存在错误
即使使用“缓存控制:无缓存”,也始终缓存具有“内容编码:gzip”的内容。
http://support.microsoft.com/kb/321722
您可以为IE6用户禁用gzip压缩(检查用户代理中的“MSIE6”)
RFC for HTTP 1.1指出,正确的方法是为以下内容添加HTTP标头:
缓存控制:无缓存
如果较旧的浏览器不符合HTTP 1.1,它们可能会忽略这一点。对于那些你可以尝试标题:
Pragma:无缓存
这也适用于HTTP1.1浏览器。
当使用浏览器的后退按钮时,BalusC提供的答案中的标题不会阻止Safari 5(以及可能更旧的版本)显示浏览器缓存中的内容。防止这种情况的一种方法是在body标记中添加一个空onunload事件处理程序属性:
<body onunload="">
这个黑客显然破坏了Safari中的前向缓存:当单击后退按钮时,是否存在跨浏览器加载事件?