关于 缓存

Cache缓存问题

 

由于IE的缓存处理机制问题,每次通过XMLHttpRequest访问动态页面返回的总是首次访问的内容,解决方法有:

1. 客户端通过添加随机字符串解决。如:
var url = 'http://url/';
url += '?temp=' + new Date().getTime();
url += '?temp=' + Math.random();

2. 在HTTP headers禁止缓存。如:

HTTP:
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
<meta http-equiv="expires" content="Thu, 01 Jan 1970 00:00:01 GMT" />
<meta http-equiv="expires" content="0" />

PHP:
header("Expires: Thu, 01 Jan 1970 00:00:01 GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");

ASP:
Response.expires=0
Response.addHeader("pragma","no-cache")
Response.addHeader("Cache-Control","no-cache, must-revalidate")

JSP:
response.addHeader("Cache-Control", "no-cache");
response.addHeader("Expires", "Thu, 01 Jan 1970 00:00:01 GMT");

3. 在XMLHttpRequest发送请求之前加上:
XMLHttpRequest.setRequestHeader("If-Modified-Since","0");
XMLHttpRequest.send(null);

posted @ 2019-02-21 10:34  G_Lybbh  阅读(189)  评论(0编辑  收藏  举报