SPUG:CGI header question

Simon Wilcox essuu at ourshack.com
Thu Jun 19 12:18:22 CDT 2003


On Thu, 2003-06-19 at 18:06, Brian Hatch wrote:
> 
> 
> > Have a look at the headers the browsers are sending with their request.
> > 
> > There should be one named If-Modified-Since. You can compare this date
> > with the modified date of your image and return a 304 (Not Modified)
> > status code instead of 200. This will cause the browser to use the
> > cached image.
> > 
> > Normally this happens automatically for images in the filesystem but you
> > have to hand code it into CGI apps.
> 
> Of course, this still requires that the CGI is being run, and that it
> queries the database to check the image timestamp.  It's less overhead
> than actually grabbing and returning the image, but the browser still
> needs to query the image each time, and the CGI must run each time.

Very true. I did also suggest the '-expires' header as you did although
the 304 route provides better granularity, particularly if you want the
browser to always have the latest version of the file.

It's a trade off between computation and bandwidth. If you're moving
large files, it's worth the computational overhead to save repeatedly
sending the file. If it's tiny navigation gifs then you might just as
well send the file anyway.

As always, TIMTOWTDI :)

Simon.



More information about the spug-list mailing list