I implemented a system to edit images displayed on a website.
When an image is edited, I want to display its last version on all pages of the site (where it's called), at least for the user who edited the image.
Now I'm searching a better way to clear the cache for a specific image than adding the timestamp to the end :
<img src="myimage.jpg?01215654" alt="" />
Why ?
It supposes to always add the timestamp at the end of the image path, with a session system for example.
But when the session expires (for example, user leaves the site, and go back few hours after), the real path of the image is displayed :
<img src="myimage.jpg" alt="" />
And the navigator randomly displays the old image, or the last version... Because Apache cached :
- myimage.jpg as the old image
- myimage.jpg?01215654 as the new version because no one hit it before (was loaded as a new media)
Limitations
- I can't change the path of an edited image, for example "myimage.jpg" to "myimage-v2.jpg", which could solve the problem...
- Images are not served from a controller (not served from a PHP script), they are direclty loaded from their path on the server.
- I don't want to use a session system that add timestamp or version string at the end of an image path with JS.
What I want
I want to say that the cache of "myimage.jpg" has expired, and so to display the last version, and then cache it normally, until the next edition. So I would like to load the image with "200 status", and not "304 modified" after an edit.
Note : when an image is edited, I reload it with JS (JQuery) in a hidden div, if you now a way to change cache header ?
So what I want is to clear the cache header of a specific image that is edited, taking into account the limitations of my project, so if possible by using cache directives without serving the image from a controller, is it possible ?