Matthew
Matthew

Reputation: 4056

How to Completely Refresh and Redownload an Image in HTML5

In JavaScript I have a function that downloads an image from the web. I am getting timing data of this process to determine start and end times, and how fast this process occurs. The issue I've run into is that for the first two times the function runs, I see separate values based on how the network speed has changed variably with time. Upon the function running consecutively after this point, the timing values do not change. Ultimately the result is that the final result remains the same for this function after the first initial run. My guess is that the data is being cached somehow in the browser. I really need this to be completely refreshed on each run of the function. How might this be possible? How I address the image is as follows

    var imageAddr = "http://www.beautyoftheweb.com/assets/images/content/development-seamless-desktop.jpg";

Upvotes: 0

Views: 110

Answers (1)

Amit Joki
Amit Joki

Reputation: 59292

Add some random query string to the image url.

Like

var imageAddr = "http://example.com/image.png?some=random-string-or-number";

That way, each image will load since the url differs each time and so there won't be any cache issues.

Upvotes: 1

Related Questions