WW.
03-14-2005, 11:53 PM
I have a CGI script that creates some PNG images. The file names of the images are based on the browser's IP address, eg "prefix.123.45.67.89.png". Typically a user will activate the script many times, and each time a new image is created, but with the same file name. (I prefer this to using a random number or the date to create the file name, because it prevents a proliferation of PNG files.)
The problem I have is that I can't seem to prevent the browser from caching the PNG file. This means the user must hit Reload while viewing the page in order to view the newly generated images.
I thought I could fix this by using another CGI script that would serve the images. E.g.
<img src="[the usual stuff]/cgi-bin/servepng.cgi?filename=file.png">
The script servepng.cgi outputs the current date, along with "Cache-control: max-age=0, must-revalidate", "Expires: -1", "Content-Type: image/png", and then it sends the PNG data.
This sometimes works, but sometimes it doesn't and the user must still hit Reload to see the new images.
Any suggestions? Am I doing something wrong? Is there a "correct" way to do this?
The problem I have is that I can't seem to prevent the browser from caching the PNG file. This means the user must hit Reload while viewing the page in order to view the newly generated images.
I thought I could fix this by using another CGI script that would serve the images. E.g.
<img src="[the usual stuff]/cgi-bin/servepng.cgi?filename=file.png">
The script servepng.cgi outputs the current date, along with "Cache-control: max-age=0, must-revalidate", "Expires: -1", "Content-Type: image/png", and then it sends the PNG data.
This sometimes works, but sometimes it doesn't and the user must still hit Reload to see the new images.
Any suggestions? Am I doing something wrong? Is there a "correct" way to do this?