I need to cache a php-generated image, but the content of the image (which must have the same URL) can change. When that happens, the browser should “uncache” the old image and cache the new one. However, if the original image is cached, the browser doesn’t send a reuest to the server.
To cache the image, I use this:
header("Cache-Control: private, max-age=10800, pre-check=10800");
header("Pragma: private");
header("Expires: " . date(DATE_RFC822,strtotime(" 2 day")));
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])
&&
(strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == filemtime($file))) {
header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($file)).' GMT',
true, 304);
exit;
}
Since the user gets all the content through ajax and JSON, I can’t (I can, but it would make the response larger) specify which image is the one I want.
You could use an ETag.
But… that still requires a http request and a “partial” response.