无法在Tomcat 8上缓存静态资源

时间:2017-03-16 14:10:48

标签: tomcat caching web.xml tomcat8

使用web.xml中的以下设置,我仍然看不到标题中的任何缓存:

curl -X HEAD -i http://localhost:8080/css/style-index.min.css?v=iris-7.23-

Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=782E2A12B148B7A53DBDD4B3C081EA33; Expires=Thu, 16-Mar-2017 17:04:34 GMT; Path=/; HttpOnly
Set-Cookie: ui=ac1b326b15ad76f38d6289; Expires=Fri, 16-Mar-2018 14:04:34 GMT; Path=/
X-FRAME-OPTIONS: SAMEORIGIN
Content-Type: text/css;charset=UTF-8
Content-Language: sv-SE-lensway
Content-Length: 5785
Vary: Accept-Encoding
Date: Thu, 16 Mar 2017 14:04:34 GMT
Connection: close


<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>

[编辑] 按照建议启用日志记录,并在日志中获得以下内容:

20-Mar-2017 10:28:35.382 FINE [http-nio-8080-exec-8] org.apache.catalina.filters.ExpiresFilter.getExpirationDate Use ExpiresConfiguration[startingPoint=ACCESS_TIME, duration=[30 DAY]] matching "text/javascript" for content-type "text/javascript;charset=UTF-8" returns 4/19/17 10:28 AM
20-Mar-2017 10:28:35.382 FINE [http-nio-8080-exec-8] org.apache.catalina.filters.ExpiresFilter.onBeforeWriteResponseBody Request "/js/1Q7231Qscripts-all.min.js" with response status "200" content-type "text/javascript;charset=UTF-8", set expiration date 4/19/17 10:28 AM

保存文件,重启服务器。

标题没有变化,尽管日志表明过期日期设置正确:设置过期日期4/19/17 10:28 AM

我错过了什么?

谢谢!

/ J

0 个答案:

没有答案