0 条
LOGO
Yutuo

最近做一个修改CSS的小项目,每次修改都需要删除浏览器缓存才能更新,于是就想把Apache设置一下,禁止浏览器缓存。

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

其基本内容如下:

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

其中,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");

Java(JSP)

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

ASP.NET

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

ASP

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

Ruby

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

Python

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

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" />

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的情况下,可以加到.htaccess文件里,也可以直接加到httpd.conf里。

发表我的评论

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址