【发布时间】:2015-11-05 07:19:54
【问题描述】:
我在我的应用程序中使用Tomcat-7, Spring-4, Hibernate-4。我尝试了两种方法来使caching 工作,但是当我检查gtmetrix 时它们似乎没有工作。
使用.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>
Approach-2 使用 Spring MVC xml 配置 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>
我可以与Tomcat, Spring-MVC 一起使用哪些其他方法来使browser caching 工作?
请分享您的经验。
【问题讨论】:
-
但是我已经接受了 Burak 的回答,但我仍然有兴趣了解
caching of static resources的更多方法。
标签: java spring-mvc tomcat caching browser-cache