禁止浏览器缓存- make sure web page is not cached
来源:互联网 发布:网络评选投票 编辑:程序博客网 时间:2024/06/08 06:49
如何禁止浏览器缓存,网上搜到的解决方法都测试无效。
基本上全都是
Cache-Control: no-cachePragma: no-cacheExpires: 0
Google了一下,找到了解决方法。
设置response header 的效果就是 返回的时候一定是重新请求页面的。
Using PHP:
header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1.header("Pragma: no-cache"); // HTTP 1.0.header("Expires: 0"); // Proxies.
Using Java Servlet, or Node.js:
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.response.setHeader("Pragma", "no-cache"); // HTTP 1.0.response.setHeader("Expires", "0"); // Proxies.
Using ASP.NET:
Response.AppendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.0.Response.AppendHeader("Expires", "0"); // Proxies.
Using ASP:
Response.addHeader "Cache-Control", "no-cache, no-store, must-revalidate" ' HTTP 1.1.Response.addHeader "Pragma", "no-cache" ' HTTP 1.0.Response.addHeader "Expires", "0" ' Proxies.
Using Ruby on Rails, or Python on Flask:
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate" # HTTP 1.1.response.headers["Pragma"] = "no-cache" # HTTP 1.0.response.headers["Expires"] = "0" # Proxies.
Using Google Go:
responseWriter.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") // HTTP 1.1.responseWriter.Header().Set("Pragma", "no-cache") // HTTP 1.0.responseWriter.Header().Set("Expires", "0") // Proxies.
Using Apache .htaccess
file:
<IfModule mod_headers.c> Header set Cache-Control "no-cache, no-store, must-revalidate" Header set Pragma "no-cache" Header set Expires 0</IfModule>
Using HTML4:
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" /><meta http-equiv="Pragma" content="no-cache" /><meta http-equiv="Expires" content="0" />
HTML meta tags vs HTTP response headers
根据SO上面的说法,如果通过HTTP访问,HTTP response headers 是优先于 meta tags 的。但
是,第一次打开是通过HTTP访问的,而返回的时候是从本地读取的。
我在自己尝试的时候,发现这两个都需要设置 才能清除页面表单记录。Google浏览器 和 IE11测试通过,页面的记录消除。其他的浏览器未测试。(推测是因为上面的原因)
如果多次测试发现 页面表单的记录还在。
但是可以保证,只要写了HTTP response headers 返回的时候一定会重新请求。
部分代码如下
<%@ page language="java" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><%response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.response.setHeader("Pragma", "no-cache"); // HTTP 1.0.response.setHeader("Expires", "0"); // Proxies.%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>index.jsp</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache, no-store, must-revalidate" ><meta http-equiv="expires" content="0" >
传送门:StackOverFlow
应用
在防止表单重复提交的时候非常有用。
2 0
- 禁止浏览器缓存- make sure web page is not cached
- Making sure a web page is not cached, across all browsers
- VBoxManage not found.Make sure virtualbox is installed and vboxmanage is in the path
- "Could not connect to AppWrapper, Please make sure TCP port 12005 is not blocked"解决方法
- Flash id does not match. Please make sure that the right flash device is selected
- could not find class file. make sure the file is compilable 解决办法
- appium1.3.7的坑-Original error: Could not initialize ideviceinstaller; make sure it is installed ...
- appium1.3.7的坑-Original error: Could not initialize ideviceinstaller; make sure it is installed ...
- appium1.3.7的坑-Original error: Could not initialize ideviceinstaller; make sure it is installed
- Could not get BatchedBridge, make sure your bundle is packaged correctly
- could not get batchedbridge, make sure your bundle is packaged correctly
- Could not get BatchedBridge, make sure your bundle is packaged properly
- Could not get BatchedBridge, make sure your bundle is packaged correctly
- could not get batchedbridge, make sure your bundle is packaged correctly
- could not get batchedbridge, make sure your bundle is packaged correctly
- Could not get BatchedBridge, make sure your bundle is packaged correctly
- Could not get BatchedBridge, make sure your bundle is packaged correctly
- postgresql无法启动,日志报错:make sure postgresql is not already running
- makefile 中$@ $^ $<的意义
- 友元函数与友元类
- ios9 之后 配置百度地图出现的错误
- JAVA
- io流
- 禁止浏览器缓存- make sure web page is not cached
- 实现ListView的 分页加载,通过点击按钮实现
- HDU 4252A Famous City
- 删除字符串中连续字符
- leetcode刷题,总结,记录,备忘 283
- Effective C++ —— 别让异常逃离析构函数
- Struts、hibernate、Spring 官网下载步骤
- C# 反射实例 一
- iOS中Bitcode的介绍及配置