IE6不缓存我的图像 [英] IE6 Not caching my images

查看:189
本文介绍了IE6不缓存我的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将我的Web应用程序上传到我的Production Tomcat Web Server中。

我正在尝试测试它并且它在FF / IE7 / IE8上工作正常但是我遇到了问题
在IE6上显示。



我注意到状态栏中IE6似乎偶尔会下载图像。
即使我没有点击任何内容,它仍会下载图像。



我使用的是一个使用图像的菜单,它在IE6上显示效果不佳。问题是我的目标用户
的60%在这个浏览器上运行。



我开始认为这是一个浏览器缓存问题。在我的所有JSP中,我将meta标记放在所有head部分中。
我这样做是因为我的应用程序严重依赖Ajax而且我需要我的网络资源的最新副本。

 < ; HEAD> 
< meta http-equiv =content-typecontent =text / html; charset = utf-8/>
< meta http-equiv =Pragmacontent =no-cache>
< meta http-equiv =Cache-Controlcontent =no-cache>
< meta http-equiv =Expirescontent =Sat,01 Dec 2001 00:00:00 GMT>
< / head>

这可能是罪魁祸首,是否有解决方法?如何强制IE6缓存这些图像?谢谢。



我不确定这是否是你想要的,但如果我遗漏了,请提出建议。



这是下载图像的示例。我忘了提到这个应用程序只在我们的本地Intranet网站上运行。



@Pekka,这是你想要的吗?

 响应标头
服务器Apache-Coyote / 1.1
Etag W /1957-1275442082000
日期星期一,2010年10月18日11:37:00 GMT

请求标题
主机atpapps03:9090
用户代理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)
接受图像/ png,图像/ *; q = 0.8,* / *; q = 0.5
接受语言en-us,en; q = 0.5
接受编码gzip,收缩
Accept-Charset ISO-8859-1,utf-8; q = 0.7,*; q = 0.7
Keep -Alive 115
连接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


解决方案


在我的所有JSP中,我将meta标记放在所有head部分中。我之所以这样做是因为我的应用程序非常依赖Ajax而且我需要最新的Web资源副本。


有两个问题:


  1. Web浏览器会忽略元标记。将此信息放在响应头中。


  2. 即使未被忽略,元规则也只适用于JSP的HTML输出,因此<在HTML输出中的所有链接资源(img,js,css等)上强>不。他们在自己的回复标题中都有自己的规则。


你最好的选择是使用 过滤器 增加了 Expires 关于静态内容的远期日期的标题。

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

public void doFilter(ServletRequest请求,ServletResponse响应,FilterChain链)抛出ServletException,IOException {
final long twoWeeksAhead = System.currentTimeMillis()+ DEFAULT_EXPIRE_TIME;
((HttpServletResponse)响应).setDateHeader(Expires,twoWeeksAhead);
chain.doFilter(request,response);
}

将此过滤器映射到 web.xml url-pattern 上覆盖感兴趣的网址,例如 / 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

解决方案

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/*.

这篇关于IE6不缓存我的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆