You have 4 free post views remaining. Please consider logging in.

Pesky Cache: Trick for Web Designers

HTML Trick for Cached Image

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

Meir
Author:

Hey Friend, Thanks for stopping by. I love feedback so please leave a comment or send me an email, thanks!

Comments from the Peanut Gallery

11 thoughts on “Pesky Cache: Trick for Web Designers”

    1. Caching serves a vital purpose in enhancing efficiency.

      1. 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!

  1. Clever way to outsmart those pesky cached images! Love the creative coding twist!

  2. This trick is super handy for keeping images fresh! Love learning new things like this.

Leave a Comment

Categories

Recent Articles

Scroll to Top

Our goal is to help people in the best way possible. this is a basic principle in every case and cause for success. contact us today for a free consultation. 

Practice Areas

Newsletter

Sign up to our newsletter