IE6 不缓存我的图像

发布于 2024-09-27 13:57:47 字数 1490 浏览 1 评论 0原文

我已将 Web 应用程序上传到生产 Tomcat Web 服务器中。
我已经在尝试测试它,它在 FF/IE7/IE8 上运行良好,但我遇到了问题 在IE6上显示。

我注意到状态栏中 IE6 似乎时不时地下载图像。 即使我没有单击任何内容,它仍然会下载图像。

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

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

<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>

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

我不太确定这是否是您正在寻找的,但如果我错过了什么,请告知。

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

@Pekka,这是你要找的吗?

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

陌上青苔 2024-10-04 13:57:47

在我的所有 JSP 中,我将所有 head 部分的元标记放在下面。我这样做是因为我的应用程序严重依赖 Ajax,并且我需要 Web 资源的最新副本。

有两个问题:

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

  2. 即使没有被忽略,元规则也仅适用于 JSP 的 HTML 输出,因此不适用于 HTML 内的所有链接资源(img、js、css 等)输出。它们在自己的响应标头中都有自己的规则。

最好的选择是使用 Filter 添加了 Expires 静态内容的远期日期标题。

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);
}

web.xml 中将此过滤器映射到覆盖感兴趣 URL 的 url-pattern 上,例如 /images/*

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

一生独一 2024-10-04 13:57:47

请参阅此问题了解如何控制静态文件的缓存设置类型。

see e.g. this question on how to control the caching settings for static file types.

你与昨日 2024-10-04 13:57:47

Pekka 是正确的,它可能是缓存控件。
解决这个问题的方法是使用一组不同的缓存标头从不同的子域加载图像。如果您使用 CDN 提供商,他们会为您设置缓存控制。

IE 很糟糕! id 在 IE 7-8-9 上测试它。很少有人用IE6
如果它是一个 Intranet 应用程序,一个快速修复方法是使用 Chrome 框架,检测它,如果未安装,则重定向到下载页面。

Pekka is correct, its likely the caching control.
A way around this would be to load your images from a different subdomain with a different set of cache headers. If you use a CDN provider, they will set the cache control for you.

IE SUCKS! id test it on IE 7-8-9. Very few use IE6
if its an intranet app, a quick fix would be Chrome frame, detect it, and if its not installed redirect to a download page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文