You Are Here Home > How to force the browser to renew a cached image with...

How to force the browser to renew a cached image with JavaScript

Yes, you can do it with JavaScript, it’s simple; assume that the name of your image 2.png and you are writing it dynamically to a web page the only thing you need to do is this:

var image = 'http://www.example.org/2.png?' + new Date().getTime();

To the browser, this is a new URL so it will download the image again but to the web server this is the same image regardless of what’s after the question mark.

Obviously you can adapt this to your own needs…

How to force the browser to renew a cached image with JavaScript
Filed under: AJAX, JavaScript, Web Development   Posted by: Codehead

Got a Question?

Get answers here.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment