Re: Repost: Non-cached graphics?
by Noone Special <pfarabee(at)indy.net>
|
| Date: |
Fri, 24 Jul 1998 09:43:07 -0500 (EST) |
| To: |
Carol Geary <caroling(at)earthlink.net> |
| Cc: |
"'hwg-graphics(at)hwg.org'" <hwg-graphics(at)hwg.org> |
| In-Reply-To: |
earthlink |
| |
todo: View
Thread,
Original
|
|
On Thu, 23 Jul 1998, Carol Geary wrote:
> Richard Hartman wrote:
> >
> > > To save
> > >disk space we wrap the file #s (at around 50).
> No, you can't control the users cache. If you are trying to save the client's
Actually, this isn't entirely correct.
One way to set up a "non-cacheable" image is to output the image from a
CGI program with a header included of "Cache-Control: no-cache".
This will cause the image to not be cached by the browser (HTTP/1.1
specification.. if you want compatibility with browsers only
understanding HTTP/1.0, use the "Pragma: no-cache" header.. or both :)
Be warned, however. CGI programming is not for casual programmers. There
are so many ways to open up your system to attack through CGI that I would
suggest finding a real professional to set it up for you. Just for
funzies, tho, here is a VERY skeletal program that will do what you need.
I know this doesn't belong here, but it was posted here, so I will
respond.. this time.
----------------------------------------------------------------------------
#!/usr/local/bin/perl
$basepath = "/www/htdocs/newlong/img/";
$file = $ENV{"QUERY_STRING"};
$file =~ s/[^\w.-_]//g; # strip out all non-filename characters
if (open(IMAGE,"< $basepath/$file")) {
print "Caching-Control: no-cache\n";
print "Pragma: no-cache\n";
if ($file=~/.gif$/i) {
print "Content-type: image/gif\n\n";
} else {
# tag any file not ending in ".gif" as a JPEG
print "Content-type: image/jpeg\n\n";
}
while (<IMAGE>) {
print;
}
} else {
print "Content-type: text/plain\n\nError opening $basepath/$file\n";
}
exit(0);
----------------------------------------------------------------------------
To use that program, just call it as:
<IMG SRC="http://www.blah.blah/whatever.cgi?image.gif">
Where image.gif is replaced with the name of the image you are wanting to
display.
If you don't want to worry about CGI, you might try doing a similar thing
in the HTML.. this may or may not do what you want, and probably won't
work in all browsers, but give this a try in the HEAD portion of your
page:
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
This should, in theory, cause the page to be reloaded every time the
browser goes to it (using a link, not the back/forward navigation)
It may or may not cascade to the objects (images) on the page as well..
you will just have to try and see :)
> itself. If the client has set the cache to a large capacity, why should you
> worry about it?
I believe they are changing images.. IE autoupdate or something.. that's
what the post sounded like, anyway.
> Are you trying to save the server's disk space? How about a different
> approach? After you generate 50 files, delete them on the server, and keep
> going with the numbers to generate new files for the client.
Personally, I am still at a loss as to how the client knows which of the
50 images is the current one.. but it's not my project, so I don't really
care :)
Pat
HWG: hwg-graphics mailing list archives,
maintained by Webmasters @ IWA
This page is part of a preserved archive of archives.hwg.org. The site is no longer active and its content is not maintained. For enquiries about this archive, write to archive(at)iwanet.org.