如何使用Tomcat启用静态内容(images,css,js)的浏览器缓存? [英] How to enable browser caching of static content(images, css, js) with Tomcat?

查看:873
本文介绍了如何使用Tomcat启用静态内容(images,css,js)的浏览器缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Tomcat启用静态内容(images,css,js)的浏览器缓存?
首选解决方案是editingspring MVC配置文件或web.xml

How to enable browser caching of static content(images, css, js) with Tomcat? Preferable solution will be editingspring MVC config files or web.xml

推荐答案

尝试(更改值)

<mvc:resources mapping="/static/**" location="/public-resources/" 
       cache-period="31556926"/>
<mvc:annotation-driven/>

您还可以使用拦截器:

<mvc:interceptors>
   <mvc:interceptor>
    <mvc:mapping path="/static/*"/>
    <bean id="webContentInterceptor" 
         class="org.springframework.web.servlet.mvc.WebContentInterceptor">
        <property name="cacheSeconds" value="31556926"/>
        <property name="useExpiresHeader" value="true"/>
        <property name="useCacheControlHeader" value="true"/>
        <property name="useCacheControlNoStore" value="true"/>
    </bean>
   </mvc:interceptor>
</mvc:interceptors>

参见 MVC docs

这篇关于如何使用Tomcat启用静态内容(images,css,js)的浏览器缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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