Page 1 of 1

Prevention of image caching

Posted: Fri Dec 08, 2006 5:10 am
by Skittlewidth
Not sure which forum this belongs in, code, client side or graphics!

I know there are various ways of controlling page caching, but could anyone tell me one that prevents image caching in browsers?
I have a logo upload script which resizes and renames a file to the id of the database entry, so when you upload a new image it overwrites the old 26.jpg for instance. The trouble is, IE still displays the old 26.jpg because it reloads it from its cache and not the server.
A second page refresh usually resolves it but it shouldn't be necessary.

Posted: Fri Dec 08, 2006 7:03 am
by feyd
Use a script to front-end the image(s). Use this script to send the no-cache header(s). :)

Posted: Fri Dec 08, 2006 7:21 am
by Skittlewidth
Not sure what you mean by using a script to frontend the images, can you explain further?

I have

Code: Select all

header("Content-type: text/html");
  header("Expires: Mon, 4 Dec 2006 05:00:00 GMT");
  header("Cache-Control: no-store, no-cache,
          must-revalidate");
  header("Cache-Control: post-check=0, pre-check=0",
          false);
  header("Pragma: no-cache");
at the top of my script, and the image tag is generated dynamically depended on what entry in the database I'm editing. Am I misunderstanding the header parameters, because it still hasn't solved the problem in IE. The images aren't cached in FireFox.

Posted: Fri Dec 08, 2006 1:02 pm
by feyd
Use a script to distribute the images. The script can send a no-cache (must revalidate) header along with the image.