Prevention of image caching

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Prevention of image caching

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Use a script to front-end the image(s). Use this script to send the no-cache header(s). :)
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Use a script to distribute the images. The script can send a no-cache (must revalidate) header along with the image.
Post Reply