Tomcat的配置为利用浏览器缓存? [英] configuring Tomcat for leveraging browser caching?

查看:1048
本文介绍了Tomcat的配置为利用浏览器缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跑了我们的web应用程序谷歌的网页速度来分析和优化我们的网站。

I ran Google's Page Speed on our web app to analyze and optimize our web site .

在一个 Web性能最佳实践中的许多项目在网页速度所列说的要利用高速缓存的全部好处一直存在于所有的浏览器,我们建议您配置Web服务器明确地设置缓存头,并将其应用到所有可缓存静态资源,不只是一个小子集(如图像)。可缓存的资源包括JS和CSS文件,图像文件和其他二进制目标文件(媒体文件,PDF,Flash文件等)。一般来说,HTML不是一成不变的,而不应被视为缓存。

One of the many items under Web Performance Best Practices as listed in Page Speed says "To take advantage of the full benefits of caching consistently across all browsers, we recommend that you configure your web server to explicitly set caching headers and apply them to all cacheable static resources, not just a small subset (such as images). Cacheable resources include JS and CSS files, image files, and other binary object files (media files, PDFs, Flash files, etc.). In general, HTML is not static, and shouldn't be considered cacheable."

我如何配置Tomcat来达到同样的?我知道它可以通过过滤器通过把一些HTTP头做,但我们可以做到这一点,而不只是配置触及code?

How do I configure tomcat to achieve the same ? I know it can be done via Filters by putting some HTTP headers but can we do it without touching code just by configuration ?

修改的:只为信息,我们使用JSF 1.2,虽然我觉得这是这个问题的背景无关

Edit : Just for information we use JSF 1.2 although I think this is irrelevant in context of this question.

推荐答案

如果您对Tomcat7,有一个内置的过滤器的。
<一href=\"http://tomcat.apache.org/tomcat-7.0-doc/config/filter.html#Expires_Filter\">http://tomcat.apache.org/tomcat-7.0-doc/config/filter.html#Expires_Filter

If you are on Tomcat7, there is a built-in filter for that. http://tomcat.apache.org/tomcat-7.0-doc/config/filter.html#Expires_Filter

我们用精彩的URlRewriteFilter做到这一点。没有code的变化,只是配置web.xml中,仅此而已。 Link和下面的规则。

We use the wonderful URlRewriteFilter to do this. No code change, just configuration to web.xml, that's all. Link and rule below.

http://tuckey.org/urlrewrite/

  <rule>
        <from>^.*\.(js|css|gif)$</from>
        <set type="expires">6 hours</set>
  </rule>

这篇关于Tomcat的配置为利用浏览器缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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