I am accessing a link on my site that will provide a new image each time it is accessed.
The issue I am running into is that if I try to load the image in the backgr
As an alternative to...
newImage.src = "http://localhost/image.jpg?" + new Date().getTime();
...it seems that...
newImage.src = "http://localhost/image.jpg#" + new Date().getTime();
...is sufficient to fool the browser cache without bypassing any upstream caches, assuming you returned the correct Cache-Control
headers. Although you can use...
Cache-Control: no-cache, must-revalidate
...you lose the benefits of the If-Modified-Since
or If-None-Match
headers, so something like...
Cache-Control: max-age=0, must-revalidate
...should prevent the browser from re-downloading the entire image if it hasn't actually changed. Tested and working on IE, Firefox, and Chrome. Annoyingly it fails on Safari unless you use...
Cache-Control: no-store
...although this still may be preferable to filling upstream caches with hundreds of identical images, particularly when they're running on your own server. ;-)
Update (2014-09-28): Nowadays it looks like Cache-Control: no-store
is needed for Chrome as well.