Solved

Making sure a image is loaded everytime.

Posted on 1998-08-11
8
185 Views
Last Modified: 2010-04-09
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?
0
Comment
Question by:cide
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 10

Expert Comment

by:MasseyM
ID: 1845198
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.


0
 

Author Comment

by:cide
ID: 1845199
What's ASP?
0
 
LVL 2

Expert Comment

by:Quixote
ID: 1845200
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.
0
 
LVL 28

Expert Comment

by:sybe
ID: 1845201
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.

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Expert Comment

by:Quixote
ID: 1845202
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.
0
 

Author Comment

by:cide
ID: 1845203
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.
0
 
LVL 28

Accepted Solution

by:
sybe earned 50 total points
ID: 1845204
When your output is generated by cgi, then you don't even need javascript to do it, you can get the time in your cgi script and just write it in the querystring.

Random numbers will work too of course, but you have to randomize them from time anyway, so why just not use time rightaway.
0
 

Author Comment

by:cide
ID: 1845205
I mean it loads cgi.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now