var image1 = new Image();
image1.src = someUrl;
// someUrl is a valid URL to a PHP file which outputs a PNG file using the imagepng function. This action caches image1 to someUrl.
image1.onload = function() {
// Some things have changed and a new image is created, which I would like to cache to someUrl.
// This is currently done by sending a session (temporary) cookie, which is recognised by the PHP file, so that it knows to take different action than the first time.
// Again, the imagepng function is used to output the image.
var image2 = new Image();
image2.src = someUrl; // this is the exact same URL
};
The desired result is to have the browser cache the image2 as a replacement of the cached image1. Unfortunately, image1 is the one that is cached, even after the image2.src = someUrl; statement.
What does work, however, is to cache image1, then create the session cookie and manually go to the someUrl page. It then does cache image2.
Is it not possible to make a browser cache an image twice, without refreshing the page?