in reply to Preventing an image from caching

The RFC'ed way to stop an image from caching is to "ship it expired". Set the Last-Modified header to now, and expires also to now, as a proper HTTP date, of course.

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re: Re: Preventing an image from caching
by belize (Deacon) on Nov 28, 2000 at 04:41 UTC
    Thanks Randal. What is the proper syntax for the above, I can't seem to find it. Would I generate the date:time within the CGI and then use a variable to place the current date and time into the header? Is there a specific syntax that the date has to be in?
      With CGI.pm, you can use the -expires switch to the header routine. Apparently, CGI::Util also has an expires routine that you can use to calculate the proper format. If you don't like digging around in the innards of CGI.pm, pull up HTTP::Date, which formats things according to the RFC. Something like this:
      use HTTP::Date qw(time2str); my $now = time2str(time); print "Expires: $now\nLast-modified: $now\n"; # add other headers here

      -- Randal L. Schwartz, Perl hacker

        Setting Expires to 0 seems to work also; I think it's in the http/1.1 RFC (RFC 2068) somewhere as an OK thing to do.

        Also the following might be relevant:
        Pragma = no-cache (http/1.0)
        Cache-Control = no-cache (http/1.1)
        (bearing in mind that proxy servers in between you and your users might be http/1.0 or http/1.1, although the 1.1 ones should be backwards compatible, presumably)

        andy.