Reputation: 185
I am using Tomcat-7, Spring-4, Hibernate-4
in my application. I have tried two approaches to make caching
work but they don't seem to be working when I checked with gtmetrix
.
.htaccess
file:<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>
mvc:interceptors
:<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/resources/*"/>
<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>
What are the other approaches that I can use with Tomcat, Spring-MVC
to make browser caching
work ?
Please share your experience.
Upvotes: 1
Views: 1649
Reputation: 953
The other approach is this:
<mvc:resources mapping="/static/**" location="/public-resources/"
cache-period="31556926"/>
<mvc:annotation-driven/>
Upvotes: 2