(网页的缓存控制)HTML配置no-cache(备忘) “Cache-control”常见的取值

HTML配置no-cache(备忘)

 

No-cache配置html


html表头以下缓存

 
    1. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
    2. <!-- HTTP 1.1 -->  
    3. <meta http-equiv="pragma" content="no-cache">  
    4. <!-- HTTP 1.0 -->  
    5. <meta http-equiv="cache-control" content="no-cache">  
    6. <!-- Prevent caching at the proxy server -->  
    7. <meta http-equiv="expires" content="0">  
    8. <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" /> 

 

“Cache-control”常见的取值有private、no-cache、max-age、must-revalidate等

网页的缓存是由HTTP消息头中的“Cache-control”来控制的,常见的取值有private、no-cache、max-age、must-revalidate等,默认为private。其做用根据不一样的从新浏览方式分为如下几种状况:
(1) 打开新窗口
若是指定cache-control的值为private、no-cache、must-revalidate,那么打开新窗口访问时都会从新访问服务器。而若是指定了max-age值,那么在此值内的时间里就不会从新访问服务器,例如:
Cache-control: max-age=5
表示当访问此网页后的5秒内再次访问不会去服务器
(2) 在地址栏回车
若是值为private或must-revalidate(和网上说的不同),则只有第一次访问时会访问服务器,之后就再也不访问。若是值为no-cache,那么每次都会访问。若是值为max-age,则在过时以前不会重复访问。
(3) 按后退按扭
若是值为private、must-revalidate、max-age,则不会重访问,而若是为no-cache,则每次都重复访问
(4) 按刷新按扭
不管为什么值,都会重复访问
服务器

当指定Cache-control值为“no-cache”时,访问此页面不会在Internet临时文章夹留下页面备份。
另外,经过指定“Expires”值也会影响到缓存。例如,指定Expires值为一个早已过去的时间,那么访问此网时若重复在地址栏按回车,那么每次都会重复访问:
Expires: Fri, 31 Dec 1999 16:00:00 GMTpost

在ASP中,能够经过Response对象的Expires、ExpiresAbsolute属性控制Expires值;经过Response对象的CacheControl属性控制Cache-control的值,例如:
Response.ExpiresAbsolute = #2000-1-1# ' 指定绝对的过时时间,这个时间用的是服务器当地时间,会被自动转换为GMT时间
Response.Expires = 20  ' 指定相对的过时时间,以分钟为单位,表示从当前时间起过多少分钟过时。
Response.CacheControl = "no-cache"
Expires值是能够经过在Internet临时文件夹中查看临时文件的属性看到的
ui

相关文章
相关标签/搜索