Have you experienced this scenario:
You updated an image and uploaded it to your website.
Your friend goes to view the page and it shows the old image still.
You franticly check the code and the file and settings to see what is going on.
The user’s web browser caches (saves) the files it downloads when visiting web pages. The purpose is for if you revisit the page in a short timeframe then it can load the local copy instead of downloading from the server.
I have a trick for you.
We can alter the HTML to force the browser to think the image is a new image every time it loads the page, which in turn causes the image to be downloaded again.
Example code:
<link rel="icon" type="image/x-icon" href="/images/favicon.ico">
We can add a fake parameter to the url of the image.
<link rel="icon" type="image/x-icon" href="/images/favicon.ico?random=1234">
Just add a question mark, a variable name (anything you want, I chose random), and assign it a value.
Some people like to do version numbers.
?v=1
?v=2
If you are using a scripting language you can have it populate a random value, my fav being simply the current timestamp.
Originally posted on Niad.Tech
Share this:
- Click to share on LinkedIn (Opens in new window)
- Click to share on Twitter (Opens in new window)
- Click to share on Facebook (Opens in new window)
- Click to share on Threads (Opens in new window)
- Click to share on Pinterest (Opens in new window)
- Click to share on X (Opens in new window)
- Click to print (Opens in new window)
- Click to email a link to a friend (Opens in new window)
11 thoughts on “Pesky Cache: Trick for Web Designers”
Caching can be so annoying, man. Good tips!
Caching serves a vital purpose in enhancing efficiency.
Caching helps speed things up, though. It’s vital!
But speed can blur the beauty of the journey.
Yo, that cache trick’s a real lifesaver, for real!
Nah, I ain’t so convinced.
No way, man! You gotta give it a shot. Sometimes, you just gotta dive in and see what happens. Life’s too short to overthink it!
Oh, you reckon? That’s rich!
That’s a bit narrow-minded.
Clever way to outsmart those pesky cached images! Love the creative coding twist!
This trick is super handy for keeping images fresh! Love learning new things like this.