【发布时间】:2011-10-04 10:48:59
【问题描述】:
我尝试了这两种方法来防止使用 PHP 和 JavaScript/jQuery 进行缓存(强制图像重新加载),但是当我通过 ajax 加载内容时,我仍然从缓存中获取图像,
PHP:
// Generate a number that will never be repeated using the time function
// that "returns the current time measured in the number of seconds since
// the Unix Epoch (January 1 1970 00:00:00 GMT)"
$cachekiller = time();
// Include the generated number in the image URL
<img src="path/to/image.png?{$cachekiller}"
Javascript/jquery:
// Generate random number between 1 and 1000.
var cachekiller = Math.floor(Math.random()*1001);
$("#thumbnail").attr("src", "path/to/image.png?"+cachekiller);
我还能做什么?
【问题讨论】:
-
这不应该被缓存,因为每次获取它的 URL 都是唯一的。你如何确定它被缓存了?
-
你是什么意思,通过ajax?
-
您将哪些缓存标头与图像一起发送?
-
大家好 - 我的意思是图像大小在服务器中经常变化,我想通过 ajax 重新加载它。
标签: php jquery image caching refresh