?
Solved

NO CACHE THANKS

Posted on 1999-07-03
8
Medium Priority
?
892 Views
Last Modified: 2008-03-03
..my little PERL program creates a very simple page with an image in it (.jpg), the image changes often, however its name is always the same.
How do I prevent browsers to cache the image avoing to display always the same one?
I tried something like  ?nocache=random  after the image link but it doesn't work.
Any suggestions?
Thanks.
0
Comment
Question by:uffa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 10

Expert Comment

by:viktornet
ID: 1213803
you should preload it in the <HEAD> section of the web page into a variable and then simply load it from that variable....
0
 

Accepted Solution

by:
anthonyu earned 150 total points
ID: 1213804
Put
Cache Control: no-cache
somewhere in the http headers your script sends the client, maybe just before
Content-type:
0
 
LVL 2

Expert Comment

by:stam061398
ID: 1213805
suppose you use CGI package :

$my_cgi = new CGI;

print $my_cgi->header(-type=>'image/gif',
                     -status=>'402 Payment Required',
               ----> -expires=>'now', <----
                     -cookie=>$my_cookie);



0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:uffa
ID: 1213806
..it will be like this?

print "Cache Control: no-cache\n\n";

or

print "<Cache Control: no-cache>\n";

is the same command works if I put it on a HTML page?
0
 
LVL 8

Expert Comment

by:jhurst
ID: 1213807
There is something wrong here.  If your ?cache=random is really a random number there is no way that this can be cached anywhere since the part after the ? is part of the URL and could not be cached.   Remember that the random function in most languages generates the same random number every time if not seeded with something that prevents this.

The no-cache method suggested above DOES NOT WORK.  Too many browsers, sadly, do not recognize it, and even those that do seem to do it for the the html of the page but not the embedded images.

I would be willing to bet that you are just not seeding the random with something equivalent to srand().

0
 

Expert Comment

by:anthonyu
ID: 1213808
Well, 2 points:

1)  You would want to use one newline if it is not the last HTTP header, 2 if it is. like

"Content-type: text/html\nCache Control: no-cache\n\n"
"Cache Control: no-cache\nContent-type: text/html\n\n"
etc.

Its an HTTP header, so no < or > unless you are doing it in HTML, like <meta http-equiv="Cache Control" content="no-cache"> which may or may not work, I have never tested that method.

2)  The "Cache control: no-cache" header is HTTP/1.1, so any compliant browser should honor it.  I know for a fact that ie5 and netscape 4.5+ do, even on images.  

If for some reason it doesn't work with a browser you need it to, try Pragma: no-cache.  That is HTTP/1.0 and should work on any browser.
0
 
LVL 8

Expert Comment

by:jhurst
ID: 1213809
I agree with anthonyu that the specs say that it works with those browsers, I just tested with MSIE 5.0 and NN 4.6 and in both cases the images were not re-loaded.  You need to be careful here, there is a potential for confusion since if they are changed then they should be detected by the server and cachine settings as needing to be re-loaded.

It would be so nice if they did work, in our corporate software we jump through hoops to get over this problem, and we use the randome method described above.
0
 

Author Comment

by:uffa
ID: 1213810
..thank you all so much.

   Content-type: text/html\nCache Control: no-cache\n\n

works perfectly.  I didn't actually test the other method since I resolved my problem using the line above, it seems ok even with ie. 4.0 and NetN. 3.0
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

719 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