NO CACHE THANKS

..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.
uffaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

viktornetCommented:
you should preload it in the <HEAD> section of the web page into a variable and then simply load it from that variable....
0
anthonyuCommented:
Put
Cache Control: no-cache
somewhere in the http headers your script sends the client, maybe just before
Content-type:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
stam061398Commented:
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
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

uffaAuthor Commented:
..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
jhurstCommented:
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
anthonyuCommented:
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
jhurstCommented:
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
uffaAuthor Commented:
..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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.