Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

no cache for images

 
Cathy Cruise
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there any code that helps no cache on images?

thanks
cathy
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the nocache meta tag and see if that helps....

Eric
 
Cathy Cruise
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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">
<META HTTP-EQUIV="Expires" CONTENT="-1">

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

Cathy
 
Yuriy Fuksenko
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
<script>
//function definition
function writeImage(imgHref,title)
{
var d = new Date();
document.writeln('<img src=\"' + imgHref + '?' + d.getTime() + '\" title=\"' + title + '\" border=0>');
}
</script>
<!-- this is how you put an image -->
<SCRIPT>writeImage('myimage.gif','test');</SCRIPT>
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic