When we update an image but the name remains the same, the browser keeps on showing the old image. This is very confusing for the admin and annoying too. If we use a decaching code, we end up reloading the image from the server on each visit and thus a lot of bandwidth is wasted.
The best solution to this is to use a URL that changes when a image is updated. The best approach to achieve this is appending a dummy part to the image src that changes when the image is updated, and what could be better than the file timestamp !!
So instead of
<img src="image.jpg" width="200">
use
The best solution to this is to use a URL that changes when a image is updated. The best approach to achieve this is appending a dummy part to the image src that changes when the image is updated, and what could be better than the file timestamp !!
So instead of
<img src="image.jpg" width="200">
use
<?php echo '<img src="image.jpg?m=' . filemtime('image.jpg') . '" width="200">'; ?>
Comments