一、对于静态页(就是通过meta标签来设置):
1 2
| <meta http-equiv="expires" content="Sunday 26 October 2008 01:00 GMT" />
|
或者通过pragma no-cache来设置,pragma出现在http-equiv属性中,使用content属性的no-cache值表示是否缓存网页(为了提高速度一些浏览器会缓存浏览者浏览过的页面,通过下面的定义,浏览器一般不会缓存页面,而且浏览器无法脱机浏览)。
1
| <meta http-equiv="pragma" content="no-cache" />
|
二、对于ASP页面:
1 2 3 4 5
| <% Response.Buffer=true Response.CacheControl="no-cache" '禁止代理服务器缓存本页面 Response.Expires=-1000 '让页面立即过期(这儿最好设置一个绝对值较大的负数) %>
|
三、对于JSP页面:
1 2 3 4 5 6 7 8 9
| <% if(request.getProtocol().compareTo("HTTP/1.0")==0){ response.setHeader("Pragma","no-cache"); } if(request.getProtocol().compareTo("HTTP/1.1")==0){ response.setHeader("Cache-Control","no-cache"); } response.setDateHeader("Expires",0); %>
|
四、对于PHP页面
1 2 3 4
| <?php header('Cache-Control:no-cache,must-revalidate'); header('Pragma:no-cache'); ?>
|
强调说明:对于动态页面,缓存的代码必须放在任何HTML标签输出之前,否则将会出错。