2017-03-15 81 views
0

我試圖把靜態資源放在瀏覽器緩存中,在研究我瞭解了有關ExpiresFilter,所以我配置它像下面的部署描述符。如何使靜態資源緩存在瀏覽器tomcat7

<filter> 
    <filter-name>ExpiresFilter</filter-name> 
    <filter-class>org.apache.catalina.filters.ExpiresFilter</filter-class> 
    <init-param> 
     <param-name>ExpiresByType image</param-name> 
     <param-value>access plus 2 weeks</param-value> 
    </init-param> 
    <init-param> 
     <param-name>ExpiresByType text/css</param-name> 
     <param-value>access plus 2 weeks</param-value> 
    </init-param> 
    <init-param> 
     <param-name>ExpiresByType application/javascript</param-name> 
     <param-value>access plus 2 weeks</param-value> 
    </init-param> 
</filter> 

    <filter-mapping> 
    <filter-name>ExpiresFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
    <dispatcher>REQUEST</dispatcher> 
</filter-mapping> 

但是,當我看到任何靜態資源說main.css的響應頭就像下面

Accept-Ranges:bytes 
Cache-Control:no-cache, no-store, max-age=0, must-revalidate 
Content-Length:47146 
Content-Type:text/css 
Date:Wed, 15 Mar 2017 10:34:09 GMT 
ETag:W/"47146-1489142922357" 
Expires:0 
Last-Modified:Fri, 10 Mar 2017 10:48:42 GMT 
Pragma:no-cache 
Server:Apache-Coyote/1.1 
X-Content-Type-Options:nosniff 
X-Frame-Options:DENY 
X-XSS-Protection:1; mode=block 

所以它不保存到瀏覽器cache.What可能是什麼原因?

+0

如果你想要更多的細節告訴我,我會發布 – Kasyap

回答

0

發生這種情況是因爲我在我的應用程序中使用了spring security,所以它重寫了響應頭文件,所以在禁用它正在工作的spring安全性的緩存控制頭之後。

相關問題