Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable browser caching of static content(images, css, js) with Tomcat?

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

like image 463
yura Avatar asked Nov 08 '10 11:11

yura


2 Answers

try (with changing the values)

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

You can also use an interceptor:

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

See the MVC docs

like image 163
Bozho Avatar answered Nov 12 '22 19:11

Bozho


If Spring 3.0 is being used, <mvc:resources> is one way to implement caching of static resources. This link has some documentation.

like image 45
Raghuram Avatar answered Nov 12 '22 17:11

Raghuram