Am trying to output an image when a Java Servlet link is called. Currently using the following:
response.addHeader("Cache-Control", "max-age=" + CACHE_INTERVAL);
response.add开发者_Python百科DateHeader("Expires", System.currentTimeMillis() + (1000*CACHE_INTERVAL));
But this still causes the images to reload from the server at times. In comparison if you look at the tags of this:
http://graph.facebook.com/502547234/picture
It never reloads again in Firefox atleast. Any suggestions? What am I missing?
Updated headers:
Mine: http://i.imgur.com/ikfVL.png
FB: http://i.imgur.com/o0KsM.png
Comparing the headers you're missing Last-Modified
field. Setting this field in your response will most likely result the browser request the image next time with a If-Modified-Since
request header field.
If not changed you can respond with 304 Not Modified
then.
Alternativly you can work with E-Tag
instead of using Last-Modified
headers when it better fits your needs.
But I am wondering about that your image is not being cached the way you do it. As far as I know you're doing the most agressive caching resulting most browsers DO NOT EVEN ASK FOR NEWER VERSION until expires
resulting in completly NO request at all. This is the most agressive caching possible.
One reason for it being not cached may be the URL you call your servlet. What does it look like?
精彩评论