tomcat7 设置静态资源的expires过期时间

<filter>
 <filter-name>ExpiresFilter</filter-name>
 <filter-class>org.apache.catalina.filters.ExpiresFilter</filter-class>
 <init-param>
    <param-name>ExpiresByType image</param-name>
    <param-value>access plus 10 minutes</param-value>
 </init-param>
 <init-param>
    <param-name>ExpiresByType text/css</param-name>
    <param-value>access plus 10 minutes</param-value>
 </init-param>
 <init-param>
    <param-name>ExpiresByType application/javascript</param-name>
    <param-value>access plus 10 minutes</param-value>
 </init-param>
</filter>
...
<filter-mapping>
 <filter-name>ExpiresFilter</filter-name>
 <url-pattern>/*</url-pattern>
 <dispatcher>REQUEST</dispatcher>
</filter-mapping>

相关链接:http://tomcat.apache.org/tomcat-7.0-doc/config/filter.html#Expires_Filter

补充:运行上述代码,js文件可能无法达到预期效果,可将application/javascript改成text/javascript,再调试一下啊(这可能是官方文档的疏忽,也可能是因为我是采用requirejs管理js文件的缘故,读者可以根据自身情况调试)。
posted @ 2013-10-09 10:34  黑色刺客  阅读(689)  评论(0编辑  收藏  举报