我在我的应用程序中使用了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>方法-2使用Spring MVC xml Config 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正常工作?
请分享你的经验。
发布于 2015-11-05 15:25:55
另一种方法是:
<mvc:resources mapping="/static/**" location="/public-resources/"
cache-period="31556926"/>
<mvc:annotation-driven/>https://stackoverflow.com/questions/33538686
复制相似问题