首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Spring MVC、Tomcat应用程序为静态资源启用浏览器缓存

使用Spring MVC、Tomcat应用程序为静态资源启用浏览器缓存
EN

Stack Overflow用户
提问于 2015-11-05 15:19:54
回答 1查看 1.3K关注 0票数 1

我在我的应用程序中使用了Tomcat-7, Spring-4, Hibernate-4。我已经尝试了两种方法来使caching工作,但当我检查gtmetrix时,它们似乎都不起作用。

使用.htaccess文件的方法1:

代码语言:javascript
复制
<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

代码语言:javascript
复制
<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正常工作?

请分享你的经验。

EN

回答 1

Stack Overflow用户

发布于 2015-11-05 15:25:55

另一种方法是:

代码语言:javascript
复制
<mvc:resources mapping="/static/**" location="/public-resources/" 
       cache-period="31556926"/>
<mvc:annotation-driven/>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33538686

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档