首页 > 其他 > 详细

禁止浏览器缓存的方法

时间:2019-11-14 10:14:59      阅读:64      评论:0      收藏:0      [点我收藏+]

把Apache设置一下,禁止浏览器缓存。

在网上找了一下,其实就是在响应头里添加禁止浏览器缓存的内容就行。

其基本内容如下:

Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0
HTTP

其中,Cache-Control用于HTTP1.1(包括1.1)以上;Pragma用于HTTP1.0;Expires用于代理服务器缓存。

各种语言的写法如下:

PHP

header("Cache-Control: no-cache, no-store, must-revalidate");
header("Pragma: no-cache");
header("Expires: 0");
PHP

Java(JSP)

response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
response.setHeader("Pragma", "no-cache");
response.setHeader("Expires", "0"); 
Java

ASP.NET

Response.AppendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
Response.AppendHeader("Pragma", "no-cache");
Response.AppendHeader("Expires", "0");
C#

ASP

Response.addHeader "Cache-Control", "no-cache, no-store, must-revalidate"
Response.addHeader "Pragma", "no-cache"
Response.addHeader "Expires", "0"
Visual Basic

Ruby

response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "0"
Ruby

Python

response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "0"
Python

HTML

<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

Apache

<IfModule mod_headers.c>
    Header set Cache-Control "no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires 0
</IfModule>
Apache

Apache的情况下,可以加到.htaccess文件里,也可以直接加到httpd.conf里。

禁止浏览器缓存的方法

原文:https://www.cnblogs.com/hcm-php/p/11854820.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!