File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes no cache for images Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "no cache for images" Watch "no cache for images" New topic

no cache for images

Cathy Cruise

Joined: Jun 13, 2004
Posts: 25
is there any code that helps no cache on images?

Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
You can use the nocache meta tag and see if that helps....

Cathy Cruise

Joined: Jun 13, 2004
Posts: 25
Here are all my META Tags,

<META HTTP-EQUIV="Cache-Control", CONTENT="no-store, no-cache, must-revalidate">
<META HTTP-EQUIV="Cache-Control", CONTENT="no-Cache">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">

yet i still see images are cached. Pages are not though.

Yuriy Fuksenko
Ranch Hand

Joined: Feb 02, 2001
Posts: 413
what you could try to do, is to add some uniq id after the image url, here is an example:
<img src="myimg.jpg?12345">

I would prefer to implement this with serverside language,but here is exampleusing javascript:
//function definition
function writeImage(imgHref,title)
var d = new Date();
document.writeln('<img src=\"' + imgHref + '?' + d.getTime() + '\" title=\"' + title + '\" border=0>');
<!-- this is how you put an image -->
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63838

If you really really want to do this "right", the url for your img tag should be a servlet which can set the caching headers as approriate and stream the image data as the response. That's really the only viable way you can control (to the extent that the browser pays attention to the headers) caching on static resources.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: no cache for images
It's not a secret anymore!