简体   繁体   English

无法通过ExpiresFilter为JavaScript文件添加Expires或Cache-Control响应标头

[英]Unable to add Expires or Cache-Control response headers for JavaScript files via ExpiresFilter

I have a website running on Tomcat 8.0.36 on Windows. 我有一个在Windows上的Tomcat 8.0.36上运行的网站。 I followed this link 我点击了此链接

https://tomcat.apache.org/tomcat-8.0-doc/config/filter.html https://tomcat.apache.org/tomcat-8.0-doc/config/filter.html

to add Expires and Cache-Control response headers. 添加Expires和Cache-Control响应标头。 Here is what I did: 这是我所做的:

<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 10 minutes</param-value>
 </init-param>
 <init-param>
    <param-name>ExpiresByType text/css</param-name>
    <param-value>access plus 10 minutes</param-value>
 </init-param>
 <init-param>
    <param-name>ExpiresByType application/javascript</param-name>
    <param-value>access plus 10 minutes</param-value>
 </init-param>
</filter>
...
<filter-mapping>
 <filter-name>ExpiresFilter</filter-name>
 <url-pattern>/*</url-pattern>
 <dispatcher>REQUEST</dispatcher>
</filter-mapping>

After adding the above in web.xml, I am able to see Expires and Cache-Control response headers for css files. 在web.xml中添加以上内容后,我可以看到CSS文件的Expires和Cache-Control响应标头。 However, I am not able to see such response headers for Javascript files. 但是,我看不到Javascript文件的此类响应标头。

Anything I did is wrong or missing? 我所做的任何事情是错误的还是丢失的?

After my tests, it seems that the correct init code for javascript should be ( x-javascript ): 经过我的测试,似乎javascript的正确初始化代码应该是( x-javascript ):

 <init-param>
    <param-name>ExpiresByType application/x-javascript</param-name>
    <param-value>access plus 10 minutes</param-value>
 </init-param>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM