我必须做什么才能使通过 HTTPS 提供的图像等内容缓存在客户端?

发布于 2024-07-04 16:40:55 字数 128 浏览 3 评论 0 原文

我使用 Tomcat 作为服务器,使用 Internet Explorer 6 作为浏览器。 我们应用程序中的网页大约有 75 张图像。 我们正在使用 SSL。 加载所有内容似乎非常慢。 如何配置 Tomcat 以便 IE 缓存图像?

I am using Tomcat as a server and Internet Explorer 6 as a browser. A web page in our app has about 75 images. We are using SSL. It seems to be very slow at loading all the content. How can I configure Tomcat so that IE caches the images?

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

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

发布评论

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

评论(7

坏尐絯 2024-07-11 16:40:55

如果您通过 https 提供页面,则需要通过 https(来自同一域或另一个域,也通过 https)提供所有包含的静态或动态资源,以避免浏览器中出现安全警告。

默认情况下,大多数浏览器不会将通过安全通道传递的内容写入磁盘,因此存在于浏览器内存缓存中,该缓存比磁盘缓存小得多。 当应用程序退出时,该缓存也会消失。

话虽如此,您可以采取一些措施来提高单个浏览器设置中 SSL 资产的缓存能力。 对于初学者,请确保所有资产都有合理的 Expires 和 Cache-Control 标头。 如果 tomcat 位于 apache 后面,则使用 mod_expires 添加它们。 这将避免浏览器必须检查页面之间的图像是否已更改

<Location /images>
   FileEtag none
   ExpiresActive on
   ExpiresDefault "access plus 1 month"
</Location>

其次,这是特定于 MSIE 和 Apache 的,大多数 apache ssl 配置都包含这些行,

SetEnvIf User-Agent ".*MSIE.*" \
     nokeepalive ssl-unclean-shutdown \
     downgrade-1.0 force-response-1.0

这些行禁用所有 MSIE 代理的 keepalive。 恕我直言,这太保守了,最后一个使用 SSL 出现问题的 MSIE 浏览器是 5.x 和未修补的 6.0 SP2 之前的版本,这两种浏览器现在都非常罕见。 以下更宽松,在使用 MSIE 和 SSL 时不会禁用 keepalives

BrowserMatch "MSIE [1-4]" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
BrowserMatch "MSIE [5-9]" ssl-unclean-shutdown

If you are serving a page over https then you'll need to serve all the included static or dynamic resources over https (either from the same domain, or another domain, also over https) to avoid a security warning in the browser.

Content delivered over a secure channel will not be written to disk by default by most browsers and so lives in the browsers memory cache, which is much smaller than the on disk cache. This cache also disappears when the application quits.

Having said all of that there are things you can do to improve the cachability for SSL assets inside a single browser setting. For starters, ensure that all you assets have reasonable Expires and Cache-Control headers. If tomcat is sitting behind apache then use mod_expires to add them. This will avoid the browser having to check if the image has changed between pages

<Location /images>
   FileEtag none
   ExpiresActive on
   ExpiresDefault "access plus 1 month"
</Location>

Secondly, and this is specific to MSIE and Apache, most apache ssl configs include these lines

SetEnvIf User-Agent ".*MSIE.*" \
     nokeepalive ssl-unclean-shutdown \
     downgrade-1.0 force-response-1.0

Which disables keepalive for ALL MSIE agents. IMHO this is far too conservative, the last MSIE browsers to have issues using SSL were 5.x and unpatched versions of 6.0 pre SP2, both of which are very uncommon now. The following is more lenient and will not disable keepalives when using MSIE and SSL

BrowserMatch "MSIE [1-4]" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
BrowserMatch "MSIE [5-9]" ssl-unclean-shutdown
一直在等你来 2024-07-11 16:40:55

通过 HTTPS 连接提供的内容永远不会在浏览器中缓存。 你对此无能为力。

通常,您网站中的图像不是很敏感,因此通过 HTTP 提供服务。

Content served over a HTTPS connection never gets cached in the browser. You cannot do much about it.

Usually, images in your web site are not very sensitive and are served over HTTP for this very reason.

为你鎻心 2024-07-11 16:40:55

第一个答案是正确的,即使用 HTTPS 时不会缓存任何内容。 但是,当您构建网页时,您可以考虑通过图像的单独 URL 来引用图像。 通过这种方式,您可以将图像指定为源自 HTTP 源,并且它们(可能)会被浏览器缓存。

The first answer is correct that nothing is cached when using HTTPS. However, when you build your web page, you may consider referencing the images by their individual URL's. This way you can specify the images as originating from an HTTP source, and they'll(likely) be cache'd by the browser.

鹿童谣 2024-07-11 16:40:55

也许您可以添加一个额外的服务器/子域来提供不带 https 的图像?

Maybe you can add an additional server/subdomain that provides the images without https?

樱&纷飞 2024-07-11 16:40:55

某些浏览器会缓存 SSL 内容。 默认情况下,Firefox 2.0+ 不会在光盘上缓存 SSL 资源(以增强隐私性)。 Firefox 3+ 不会将它们缓存在光盘上,除非出现 Cache-control:public 标头。

因此,请正确设置 Expires: header 和 Cache-control:public。 例如

<Files ~ "\.(gif|jpe?g|png|ico|css|js|cab|jar|swf)$">
        # Expire these things
        # Three days after access time
        ExpiresDefault  "now plus 3 days"
        # This makes Firefox 3 cache images over SSL
        Header set Cache-Control public
</Files>

Some browsers will cache SSL content. Firefox 2.0+ does not cache SSL resources on disc by default (for increased privacy). Firefox 3+ doesn't cache them on disc unless the Cache-control:public header appears.

So set the Expires: header correctly and Cache-control:public. e.g.

<Files ~ "\.(gif|jpe?g|png|ico|css|js|cab|jar|swf)$">
        # Expire these things
        # Three days after access time
        ExpiresDefault  "now plus 3 days"
        # This makes Firefox 3 cache images over SSL
        Header set Cache-Control public
</Files>
无人问我粥可暖 2024-07-11 16:40:55

如果这 75 个图像中有很多是出现在每个页面上的图标或图像,则可以使用 CSS 精灵来大幅减少 HTTP 请求的数量,从而更快地加载页面:

http://www.alistapart.com/articles/sprites/

If a lot of those 75 images are icons or images that appear on every page, you can use CSS sprites to drastically reduce the number of HTTP requests and thus load the page faster:

http://www.alistapart.com/articles/sprites/

治碍 2024-07-11 16:40:55

75 张图片听起来很多。 如果是很多小图像,可以通过多种方法将许多图像捆绑为一个,您可能会看看是否可以找到一个可以做到这一点的库。 此外,您还可以强制将图像缓存在 google gears 等内容中。

75 images sounds like a lot. If it is a lot of small images, there are ways of bundling many images as one, you might see if you can find a library that does that. Also you can probably force the images to be cached in something like google gears.

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