Forum Moderators: coopster
The problem is that when users try to replace an image they uploaded, the new image they choose takes the name of the old one on the server - but they continue seeing the original (deleted) one due to the browser just serving the cached version.
So far I see two solutions, both of which I'm not too happy with.
1. Prevent these images from being cached altogether (for everyone) - will start hogging bandwidth, technically, it's ok if images are cached for regular users
2. Give each newly uploaded image a unique name instead of replacing the original one - harder to keep track of 'current' images, will need a big change throughout the site.
Any ideas? As you can see, easiest solution is to simply prevent cached images from displaying on the user 'Control Panel'.
Thanks
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate("D, d M Y H:i:s").' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
That is an easy solution that should take very minimal additional work to install on your site.
<edit>
To combat the use of bandwidth are you compressing your pages?
You could also use the query string on the url to tell the browser that the page needs to be reloaded when the image is updated i.e.
first page load example.com/my_page.php
image updates example.com/my_page.php?image=updated
or something like that.
[edited by: PHP_Chimp at 1:47 pm (utc) on Jan. 28, 2009]
Actually my page is already 'non-cacheable', i.e. I do have the no-cache headers you mentioned (not exactly same). But these only seems to affect the actual content of the page (the source). Once the browser (FireFox in my testing) comes to a tag of an image it has already loaded before, it just sticks the cached version onto the page.
The only way I could get images to be re-loaded every time is through no-cache headers in htaccess. But again, this doesn't seem very efficient since the images are reloaded too often.
In any case, I think I can just stick some random parameters on the images in the specific page I want them to get updated constantly. i.e. /images/img1.jpg?1234
So instead of
/path/to/img.jpgyou end up with
/path/to/img.jpg?1233192415