Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
478 views
in Technique[技术] by (71.8m points)

internet explorer - IE6 Not caching my images

I uploaded my web application already in my Production Tomcat Web Server.
I am trying to test it already and it works fine on FF/IE7/IE8 but I am having a problem on display on IE6.

I notice in the status bar that IE6 seems to be downloading the images every now and then. Even though I did not click anything, it still downloads the images.

I am using a menu that uses images and it does not display well on IE6. Problem is that 60% of my targeted user runs on this browser.

I am beginning to think that this is a browser cache problem. In all my JSP, I place below meta tag in all the head section. I did this because my apps relies heavily on Ajax and I need the latest copy of my web resource.

<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Expires" content="Sat, 01 Dec 2001 00:00:00 GMT">
</head>

Could this be the culprit and is there any workaround for this? How can I force IE6 to cache those images? Thanks.

I am not exactly sure if this is what you are looking for but kindly advise if I miss anything.

This is an example of an Image being downloaded. I forgot to mention that this apps runs only on our local intranet web site.

@Pekka, Is this what you are looking for?

Response Headers
Server  Apache-Coyote/1.1
Etag    W/"1957-1275442082000"
Date    Mon, 18 Oct 2010 11:37:00 GMT

Request Headers
Host    atpapps03:9090
User-Agent  Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10 ( .NET CLR 3.5.30729)
Accept  image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive  115
Connection  keep-alive
Referer http://atpapps03:9090/rts/css/menu.css
Cookie  JSESSIONID=0DD210EE0B2788A7774B10D477734DA9
If-Modified-Since   Wed, 02 Jun 2010 01:28:02 GMT
If-None-Match   W/"1957-1275442082000"
Cache-Control   max-age=0
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In all my JSP, I place below meta tag in all the head section. I did this because my apps relies heavily on Ajax and I need the latest copy of my web resource.

There are two problems:

  1. The meta tags are ignored by the webbrowser. Put this information in the response header.

  2. Even when it wasn't ignored, the meta rules would only apply on the HTML output of the JSP and thus not on all linked resources (img, js, css, etc) inside the HTML output. They have each their own rules in their own response header.

Your best bet is using a Filter which adds the Expires header on a far-future date on static content.

private static final long DEFAULT_EXPIRE_TIME = 604800000L; // ..ms = 1 week.

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
    final long twoWeeksAhead = System.currentTimeMillis() + DEFAULT_EXPIRE_TIME;
    ((HttpServletResponse) response).setDateHeader("Expires", twoWeeksAhead);
    chain.doFilter(request, response);
}

Map this filter in web.xml on an url-pattern covering the URL of interest, e.g. /images/*.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...