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
};
期望的结果是让浏览器缓存 image2 作为缓存的 image1 的替换。不幸的是, image1 是被缓存的,即使在image2.src = someUrl;
语句之后也是如此。
但是,有效的是缓存 image1,然后创建会话 cookie 并手动转到 someUrl 页面。然后它会缓存 image2。
不刷新页面就不能让浏览器缓存两次图像吗?