1

I am using tomcat 8 with spring . I want to cache few specific image in browser. How can i achieve that.

I Checked This but i didn't get how to specify a specific image file. From the server side i creating and sending img as below

        strBuilder.append("<img src='");
        strBuilder.append("/resources/images/nophotos/no_photo_171x180.png");
        strBuilder.append("' alt='");
        strBuilder.append("");
        strBuilder.append("'/>"); 

and on the client side i get it like <img src='/resources/images/nophotos/no_photo.png' alt='' />

Is there any other way to specify image caching ?

Community
  • 1
  • 1
Manish Kumar
  • 10,214
  • 25
  • 77
  • 147

1 Answers1

0

You cache the image by setting the caching headers where the image is actually returned. Your HTML is just code for requesting an image, so that's not where the caching info goes.

You can use Tomcat's Expires Filter to set caching headers:

http://tomcat.apache.org/tomcat-7.0-doc/config/filter.html#Expires_Filter

Neil McGuigan
  • 46,580
  • 12
  • 123
  • 152
  • using expire filter will cache even dynamic images that i dont want. i only want to cache static file. in spring i saw there is someting `` but the problem is it doesnt use browser cache evry time sent a http request to server and in response it gets 304 response – Manish Kumar Dec 03 '14 at 02:24
  • @Manish If browser is sending 304 then it is caching, just not the way you want. see http://stackoverflow.com/questions/3934413/chrome-why-is-it-sending-if-modified-since-requests – Neil McGuigan Dec 03 '14 at 03:29