Link to home
Start Free TrialLog in
Avatar of cide
cide

asked on

Making sure a image is loaded everytime.

Hi,
    How do I make sure an image is not loaded from the cache but rather from the site everytime.  They way I can think of doing this is not putting the image in the cache in the first place, but how do I do this?
Avatar of MasseyM
MasseyM

You can set the expiration date for the page... Using ASP, you would simply use:

<% response.expires = Now()%> This will keep the picture out of the cache... I am not sure how to do it outside of ASP though... So, maybe someone else knows how to pass an HTML header to a browser.


Avatar of cide

ASKER

What's ASP?
Even if you could code your page in ASP, this wouldn't do it.  The browser would understand that the page expires from cache immediately, but the stuff *in* the page wouldn't expire.

Otherwise, I would suggest using the plain-Jane HTML tag in the <head>

<meta http-equiv="Expires" content="January 1, 1970 00:00:00 GMT">

But I don't think that'll work.
Avatar of sybe
Use javascript to give the picture a time dependent querystring:

<script>
now = new Date();
document.write("<img src='yourimage.jpg?"+escape(now)+"' width=50 height=50 border=0>");
</script>

This way the browser will it's a different image every time and not get it from the cache.


By the way ASP is Active Server Pages, it has to do with scripting. It is like javascript (or vbscript), but the script is executed at the server. The browser just sees HTML.

Sybe's solution works.  I've used it before.  I didn't think of it because I had such a bad experience with the technique, one you will want to avoid:

Using Sybe's technique, the same image is downloaded and put into cache each time the page is rendered.  It is never called from cache, which is what you want.  However, in a single browsing session, if this page is rendered often, then this image can rapidly choke the cache.  We used this technique in an ad-frame that refreshed every 20 seconds -- which meant that every 20 seconds a new cache-entry was being made.  Choked us up big time if the user hung out for an hour.

In general, go with his technique if you only are goign to load the page less than 50 times or so; less if the image is big.
Avatar of cide

ASKER

The problem is it's actually a cgi program so I'll have to modify my cgi code.  That's no biggy though.  I was thinking of the same thing you guys were except use a random number.
ASKER CERTIFIED SOLUTION
Avatar of sybe
sybe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cide

ASKER

I mean it loads cgi.