View Full Version : prevent loading of cached image

02-20-2004, 06:12 PM
Is there some way that I can not load one image from the cache? It is replaced all of the time, and needs to not load from the cache.

02-20-2004, 06:22 PM
I dont know if this will apply to images aswell but you could try:

<meta http-equiv="pragma" content="no-cache" />

02-20-2004, 07:41 PM
Doesn't that code prevent things from going into the cache? I want pages and images to be cached. On a certain page, I want the image that is loaded to not load from the cache. Does that make sense?

It's not that I want an image to be prevented from being cached, I just don't want it to be loaded from that cache when it is referenced in a particular page.

02-20-2004, 08:26 PM
Do you have any form of server-side access. Im not sure about ways to specificly say what can be loaded from the cache and what not, but If you could access PHP you could use something like:

<a href="image.php" alt="Blah" />

then have:

header("Content-Type: image/jpeg");

which should in theory reload the image every time

Roy Sinclair
02-20-2004, 08:57 PM
If your page is coming from a server side script (PHP or otherwise) you can use this simple technique:

<img src="myimage.png?insert datetime stamp here" alt="Some text" />

Use whatever function in your server side script that'll put the current date and time into that space after the ?.

Please note that missing-score meant use: <img src="image.php" alt="Blah" /> and accidently wrote an <a> tag instead.

02-20-2004, 09:18 PM
yeh sorry about that :rolleyes: :p

02-20-2004, 09:31 PM
Yes, I am using php...so that will hopefully work! Thank you very much!

Willy Duitt
02-20-2004, 09:33 PM
Here is a javascript solution which is much like Roy's suggestion in that it adds the UTC Time to a querry at the end of the image URL. If you check your TIP files you will find a different image cached eac time the page is called.

<script type="text/javascript">
var myImage = new Image()
myImage.src = 'http://www.stadiumsofnfl.com/afc/aldelph102.jpg?';
function chkCache() {
var clocktime = new Date();
var utchours = clocktime.getUTCHours();
var utcminutes = clocktime.getUTCMinutes();
var utcseconds = clocktime.getUTCSeconds();
var utcyear = clocktime.getUTCFullYear();
var utcmonth = clocktime.getUTCMonth()+1;
var utcday = clocktime.getUTCDate();
var utctime = utcyear + utcmonth + utcday;
utctime += utchours + utcminutes + utcseconds;

isNew = myImage.src;
if(!isNew.match('#')) {
document.images['noCache'].src = myImage.src+utctime;
else{document.images['noCache'].src = document.images['noCache'].src;

<BODY onload="chkCache()">
<img name="noCache" src="http://www.stadiumsofnfl.com/afc/aldelph102.jpg" width="640" height="480" alt="Adelphia Coliseum">


02-20-2004, 09:39 PM
The php solution may be a better idea as people may have javascript disabled although both should work fine.

Roy Sinclair
02-20-2004, 10:46 PM
If you go with the PHP solution, make your image script as specified. If you decide to write a "generic" script which can be used to pick off any image using a parameter passed on the URL (<img src="image.php?actualimagename.jpg" alt="Hah" />) you must also add code to the PHP script to validate the image name returned, otherwise you've opened a hole for hacking into your site and the hackers may do something like this: <img src="image.php?image.php" alt="Gotcha" /> and be able to read your scripts merely by looking in their cache.

02-21-2004, 03:35 PM
I went with your original post, Roy, and it works great. Thanks.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum