Reload image doesn't refresh
function updateimage(){
$("#fileimg").attr("src","path/to/开发者_运维问答image.jpg");
$('#fileimg').fadeIn('slow');
setTimeout(updateimage, 5000);
}
Hey,
I want to reload an image every 5 seconds but that doesn't work, it stays the same, but when you F5 the page it do refreshes. How can i refresh it every 5 sec normally that the image updates too?
It's cached, so it doesn't need to reload. If you want to force a fresh load you need to make the browser think it's a different file:
function updateimage(){
$("#fileimg").attr("src","path/to/image.jpg?" + new Date());
$('#fileimg').fadeIn('slow');
setTimeout(updateimage, 5000);
}
Is there a solution that respects http caching? If the image only changes sometimes, it would be great not to force every client to do a complete reload.
E.g. I have a webcam pic that updates every 5 seconds. Even if each client does a ?dateMillis reload every 5 seconds, intermediate caches will still not correctly reuse the data between clients. Allowing standard cache timeouts (or even etag checks) to work would save a lot of resources.
精彩评论