Ezilon.com - Target Your Audience, be Seen in Your Region

flushing the cache for just one image?

You are viewing this site as a guest. Join our community to get your questions answered and share knowledge. Active members may advertise and ask for a website critique.

They have: 20 posts

Joined: Sep 2006

I have updated an image called heart.jpg on my website.

How do I make sure that the new one displays when a user re-visits my website, rather than the old one they have in their cache?

Tks,

JeevesBond's picture
Moderator

He has: 3,710 posts

Joined: Jun 2002

You might find a way to do this, although it's not worth the effort. I've found that browsers can be reasonably intelligent about using their cache. One way to 'fool' them into updating is use a different filename for the image, then--as long as the browser gets the new version of your page--it will use the new image.

The file name would be something like: heart02.jpg, or heartnew.jpg Hope this helps. Smiling

a Padded Cell our articles site!

andy206uk's picture
DeveloperModerator

He has: 1,754 posts

Joined: Jul 2002

I wonder if this would work:

<img src="filename.jpg?r=<?= time() ?>" with="50" height="50" alt="etc" />'

I used something similar to prevent caching of a dynamically generated css file once and it worked a treat...

Andyk

Blog of a Web Designer
Give a man a fish and you feed him for a day. Teach him to use the Net and he won't bother you for weeks.

They have: 20 posts

Joined: Sep 2006

Thanks,----- are you calling a function here time() ....is it something in your header?

He has: 11 posts

Joined: Feb 2007

<? time(); ?> is a php function...

If you want to use Javascript you will need to make a function that will either create a random number and attach it to the end of the image, or create an array that will randomly select one to show.

ACJavascripts.com - Free Cut and Paste Javascripts
SimplyProgram.com - Personal Blog
CYWebmaster.com - Webmaster Forum (re-designing)