禁止浏览器缓存数据
2013-05-24 15:05
471 查看
1. Cache-Control头域
Cache-Control指定请求和响应遵循的缓存机制。在请求消息或响应消息中设置Cache-Control并不会修改另一个消息处理过程中的缓存处理过程。请求时的缓存指令包括no-cache、no-store、max-age、max-stale、min-fresh、only-if-cached,响应消息中的指令包括public、private、no-cache、no-store、no-transform、must-revalidate、proxy-revalidate、max-age。各个消息中的指令含义如下:
Public指示响应可被任何缓存区缓存。
Private指示对于单个用户的整个或部分响应消息,不能被共享缓存处理。这允许服务器仅仅描述当用户的部分响应消息,此响应消息对于其他用户的请求无效。
no-cache指示请求或响应消息不能缓存
no-store用于防止重要的信息被无意的发布。在请求消息中发送将使得请求和响应消息都不使用缓存。
max-age指示客户机可以接收生存期不大于指定时间(以秒为单位)的响应。
min-fresh指示客户机可以接收响应时间小于当前时间加上指定时间的响应。
max-stale指示客户机可以接收超出超时期间的响应消息。如果指定max-stale消息的值,那么客户机可以接收超出超时期指定值之内的响应消息。
[b]2.response.setHeader("Cache-Control","no-cache");[/b]
This is used to prevent the browser from caching your dynamic content generated by a JSP or Servlet.
You set this attribute in the HTTP header of the response object which would tell the browser not to cache this content. So everytime you request the page again, the browser would make a new request, instead of showing you a cached page.
[b]3.使用服务器端控制AJAX页面缓存:[/b]
response.setHeader( "Pragma", "no-cache" );
response.addHeader( "Cache-Control", "must-revalidate" );
response.addHeader( "Cache-Control", "no-cache" );
response.addHeader( "Cache-Control", "no-store" );
response.setDateHeader("Expires", 0);
单纯的使用 xmlhttp.setRequestHeader("Cache-Control","no-cache")无效。
4.在head中增加meta信息:
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
Cache-Control指定请求和响应遵循的缓存机制。在请求消息或响应消息中设置Cache-Control并不会修改另一个消息处理过程中的缓存处理过程。请求时的缓存指令包括no-cache、no-store、max-age、max-stale、min-fresh、only-if-cached,响应消息中的指令包括public、private、no-cache、no-store、no-transform、must-revalidate、proxy-revalidate、max-age。各个消息中的指令含义如下:
Public指示响应可被任何缓存区缓存。
Private指示对于单个用户的整个或部分响应消息,不能被共享缓存处理。这允许服务器仅仅描述当用户的部分响应消息,此响应消息对于其他用户的请求无效。
no-cache指示请求或响应消息不能缓存
no-store用于防止重要的信息被无意的发布。在请求消息中发送将使得请求和响应消息都不使用缓存。
max-age指示客户机可以接收生存期不大于指定时间(以秒为单位)的响应。
min-fresh指示客户机可以接收响应时间小于当前时间加上指定时间的响应。
max-stale指示客户机可以接收超出超时期间的响应消息。如果指定max-stale消息的值,那么客户机可以接收超出超时期指定值之内的响应消息。
[b]2.response.setHeader("Cache-Control","no-cache");[/b]
This is used to prevent the browser from caching your dynamic content generated by a JSP or Servlet.
You set this attribute in the HTTP header of the response object which would tell the browser not to cache this content. So everytime you request the page again, the browser would make a new request, instead of showing you a cached page.
[b]3.使用服务器端控制AJAX页面缓存:[/b]
response.setHeader( "Pragma", "no-cache" );
response.addHeader( "Cache-Control", "must-revalidate" );
response.addHeader( "Cache-Control", "no-cache" );
response.addHeader( "Cache-Control", "no-store" );
response.setDateHeader("Expires", 0);
单纯的使用 xmlhttp.setRequestHeader("Cache-Control","no-cache")无效。
4.在head中增加meta信息:
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
相关文章推荐
- HTTP Server如何禁止浏览器缓存数据
- 禁止客户端的浏览器缓存数据
- 禁止ajax缓存获取程序最新数据的方法
- php添加http头禁止浏览器缓存
- 禁止表单自动提示缓存数据
- 禁止浏览器缓存所有动态页面的过滤器:
- bug 由于浏览器缓存而引起的ajax请求并没有获取到服务器最新数据从而导致的bug
- jsp中如何避免客户端浏览器在刷新时,使用缓存的数据
- 谷歌浏览器(Chrome)禁止浏览器缓存 设置
- 2013-01-28 09:46 PHP阻止页面后退如何用PHP实现禁用浏览器的后退,使后退的页面失效或链接到别的地方?使用php禁止浏览器缓存?
- 禁止from disk cache,禁止浏览器缓存问题
- javaweb之response随机生成图片验证码加载到web页面中(本实例使用了禁止浏览器缓存头),并且单击使用javascript换图片
- 禁止浏览器缓存(适合火狐和IE)
- JavaWeb禁止浏览器缓存当前Web页面的方法
- 通过自定义Filter(适配器),并实现浏览器的禁止缓存的Filter
- 禁止浏览器缓存动态资源,例如JSP资源
- 谷歌浏览器(Chrome)禁止浏览器缓存 设置
- Java禁止浏览器有缓存的源码
- 禁止后退按钮和浏览器刷新后不缓存
- 使用Filter指定浏览器来缓存或不缓存服务器数据