I'm sure many site admins must deal with this sort of problem all the time, but I don't have a really good and simple solution myself. It is what happens when you overwrite an existing image on the server. The site visitor's browser still displays the old one and must be refreshed to see the updated image (and stylesheet for that matter).

So is there any simple solution to trick the browser to refresh the cache when there's a new image using the old name? And yes, of course the obvious solution is to rename the image, but please bear with me on this and assume that's not always a good solution...

And this is for Drupal sites in case that bears on the question.


ANSWER: Based on the answer below, I am now using this code:

echo 'niceimage.jpg?'.date("dmHi", filemtime('niceimage.jpg'));

This automatically updates the image query string whenever the image-file is changed, based on the modification date of the image-file.

1 Answer 1


One common way to do this is to append a query string to the name of the file like this:


Appending the query string essentially "renames" the file so the browser will fetch the file. The query string is obviously useless to an image or stylesheet or other static files so it is ignored and won't break anything.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.