如何在 Apache Tomcat 中的单个 JS 文件上设置 Expires HTTP 标头?
我有一个 js
文件,该文件缓存 5-10 分钟,具体取决于我是从 Eclipse 使用 tomcat(通过 GWT 插件)还是将 tomcat 作为独立启动。
这很奇怪,因为我使用 GWT 作为我的框架,并且这个文件根本不应该被缓存(对于那些了解 GWT 的人来说,它是一个 nocache.js 文件)。 我读过 GWT Google 群组帖子这是一个容器配置问题,而在其他地方,我需要在包含的 HTML 文件中定义它。
基本上,我现在很困惑,因为我不知道如何让这个文件不缓存。 请注意,这个js是由GWT
生成的,我无法修改它。
感谢您的帮助, 一泰
I have a js
file which is cached between 5-10 minutes, depending on whether I'm using tomcat from the eclipse (via GWT plugin) or starting tomcat as standalone.
This is strange as I'm using GWT
as my framework and this file should not be cached at all (it's a nocache.js file to those of you who know GWT).
I've read on a GWT Google group thread that it's a container configuration issue, and somewhere else that it's something I need to define in the containing HTML file.
Basically, I'm confused right now as I have no clue on how to get this file to not cache.
Please note that this js is generated by GWT
and I cannot modify it.
Thanks for any help,
Ittai
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 javax.servlet.Filter
以可移植的方式(跨不同的应用程序服务器)执行此操作的一种方法是使用过滤器。在 web.xml 中添加以下内容:
然后实现 MyHeadersFilter,如下所示:
:可配置过滤器
您还可以使用
s 从 web.xml 中配置过滤器:可选 将以下内容添加到 MyHeadersFilter:
这使得可以使用以下方式访问您的 init-param:
Using a javax.servlet.Filter
One way to do this in a portable way (across different app servers), is using Filters. In your web.xml add the following:
Then implement your MyHeadersFilter like:
Optional: Configurable Filters
You can also make your filter configurable from your web.xml, by using
<init-param>
s:Add the following to MyHeadersFilter:
That makes it possible to access your init-param(s) using:
tomcat 7 中有一个 Filter 可用,
您可以在此处找到更多详细信息
https://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/filters/ExpiresFilter.html
There is a Filter available in tomcat 7
You can find more details here
https://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/filters/ExpiresFilter.html