我正在尝试将静态资源放在浏览器缓存中,在研究我了解ExpiresFilter时,所以我在部署描述符中配置如下所示。
<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
所以它没有保存到浏览器缓存中。可能是什么原因?
答案 0 :(得分:0)
这种情况正在发生,因为我在我的应用程序中使用了spring安全性。所以它覆盖了响应标头,所以在我从spring安全性中禁用了缓存控制标头之后它正在工作。