11 Vote

PHP: Force Reload of Image or other Content

Question by Anja Proggy | Last update on 2023-01-13 | Created on 2014-06-29

On my website, I am using an image that is created dynamically. I know that it is a good thing to cache images and other content - but the good this behavior is for the performance, the obstructive it is to me with this dynamic image.

Again and again, an old image loaded from the browser cache is shown on my website instead of the current version that is up-to-date.

How is it possible to achieve, that this individual image (or any of the content) will be refreshed with every page impression independent from any cached content?

ReplyPositiveNegative
2Best Answer4 Votes

Just attach a dynamic "version number" to the image URL. 

So, for example, something like this :

echo '<img src="img.png?t='.time().'">';

With t=time() at the end of the URL, the browser is lead to believe, that it is always another image, because the time created with time() is always different with every site view.

Of course, you do not have to parse or use of the parameter "t" in any way, you are just presenting the image you would like to show.

More on this also in the tutorial about reloading despite the browser cache.
Last update on 2023-01-13 | Created on 2014-06-30

ReplyPositive Negative
Reply

Related Topics

PHP: File Download Script

Tutorial | 0 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.