1
我在我的应用程序中使用了Tomcat-7, Spring-4, Hibernate-4
。我已经尝试了两种方法来使caching
工作,但他们似乎没有工作,当我检查gtmetrix
。使用.htaccess
文件
使用Spring MVC,Tomcat应用程序为静态资源启用浏览器缓存
方法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>
使用Spring MVC XML配置
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>
什么是我可以用其他的方法用Tomcat, Spring-MVC
使browser caching
工作?
请分享你的经验。
但是我已经接受了布拉克的答案,但我还是想知道的静态资源的''缓存更多的办法。 – Peter