[英]Enable browser caching for static resources with Spring MVC,Tomcat application
I am using Tomcat-7, Spring-4, Hibernate-4
in my application. 我在应用程序中使用
Tomcat-7, Spring-4, Hibernate-4
。 I have tried two approaches to make caching
work but they don't seem to be working when I checked with gtmetrix
. 我尝试了两种方法来使
caching
起作用,但是当我使用gtmetrix
检查时,它们似乎gtmetrix
。
.htaccess
file: .htaccess
文件的方法1: <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
方法2: <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 ? 我可以将
Tomcat, Spring-MVC
使用哪些其他方法来使browser caching
正常工作?
Please share your experience. 请分享您的经验。
The other approach is this: 另一种方法是这样的:
<mvc:resources mapping="/static/**" location="/public-resources/"
cache-period="31556926"/>
<mvc:annotation-driven/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.