HTTP 缓存标头
我有一些在网页中动态加载图像的 javascript 代码:
imageSrc = pid.toString() + '/' + imageName + '/' + num.toString();
//imageSrc = pid.toString() + '/' + imageName;
第一行工作正常,但使用第二行会导致图像在加载后不会更改。我使用 firebug 从服务器捕获标头:
Content-Length 43
Allow GET, HEAD
Expires Sun, 28 Jan 2007 00:00:00 GMT
Server CherryPy/3.1.2
Pragma no-cache
Cache-Control no-cache, must-revalidate
Date Sun, 13 Feb 2011 21:12:31 GMT
Content-Type image/x-png
并且我还添加了行 到网页的头部。
该问题出现在firefox、IE、chrome中,所以我认为这一定是一个根本性的问题,而不是浏览器的问题。任何帮助将不胜感激。
I have some javascript code that loads images dynamically in a web page:
imageSrc = pid.toString() + '/' + imageName + '/' + num.toString();
//imageSrc = pid.toString() + '/' + imageName;
The first line works fine, but using the second line causes the images to not change after being loaded. I used firebug to capture the headers from the server:
Content-Length 43
Allow GET, HEAD
Expires Sun, 28 Jan 2007 00:00:00 GMT
Server CherryPy/3.1.2
Pragma no-cache
Cache-Control no-cache, must-revalidate
Date Sun, 13 Feb 2011 21:12:31 GMT
Content-Type image/x-png
And I've also added the line <meta http-equiv="Cache-control" content="no-cache">
to the head of the web page.
The problem occurs in firefox, IE, and chrome, so I think it must be a fundamental problem, and not a browser issue. Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
击败缓存的典型方法是附加一个搜索字符串(注意 PNG 后面的问号):
顺便说一句,您不需要执行 .toString(),因为将变量添加在一起的行为使它们成为一个字符串:
The typical way to defeat the cache is to append a search string (note the question mark after PNG):
BTW, you don't need to do .toString(), because the act of adding variables together makes them a string: