[英]Enable browser caching for static resources with Spring MVC,Tomcat application
我在應用程序中使用Tomcat-7, Spring-4, Hibernate-4
。 我嘗試了兩種方法來使caching
起作用,但是當我使用gtmetrix
檢查時,它們似乎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>
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
正常工作?
請分享您的經驗。
另一種方法是這樣的:
<mvc:resources mapping="/static/**" location="/public-resources/"
cache-period="31556926"/>
<mvc:annotation-driven/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.