Thew
Thew

Reputation: 15959

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?

Upvotes: 0

Views: 571

Answers (2)

drewp
drewp

Reputation: 316

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.

Upvotes: 1

Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114417

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); 
}

Upvotes: 6

Related Questions