How to force a Ctrl F5 refresh on a single page when it loads to make sure the images on the server are loaded and not from the cache

Hi All

I hope I have posted in the right location.

I have made a page in my admin area in PHP 7.3 that uploads a file and overwrites the one that is currently on the server.

The issue I am having is that when I come back to the upload page I have the image on it and the browser is pulling in the cached image rather than the one on the server.

I have done quite a bit of research and think JavaScript might be the way to force a Ctrl F5 refresh but can’t work out how.

I don’t mind what sort of code I use as long as it works.

Can you help please?

mrmbarnes

Try adding a parameter to the image URL:

<img src="image.jpg?date=20190905" alt="#" >

Also try deleting the image, refreshing the page, ensure the image is not showing then upload the new image.

Thanks… adding the date option worked

1 Like

FWIW, this is called cache busting.

2 Likes

Very good article, great and simple explanations instead of just “copy & paste this”.