apache - htaccess mod_headers 用于无缓存

标签 apache jsp caching http-headers mod-headers

我们有一个应用程序,允许用户添加/编辑/替换/删除内容(文本、图像、swf、mp3 等)。我们希望管理员通过使用无缓存 header 始终拥有最新更新的文件,并且当用户运行应用程序时,所有内容都会获取/使用缓存。

我研究了解决方案并尝试使用 html 元标记,例如:

<meta http-equiv="expires" content="0" />
<meta http-equiv="cache-control" content="no-cache, no-store" />
<meta http-equiv="pragma" content="no-cache" />

但这似乎不是一个好的解决方案,因为这种情况发生在创建 header 之后,并且不会更改媒体(图像、swfs、mp3 等) header 。

我想使用 apache 设置 header ,并遇到了 this site 的代码:

<filesMatch "\.(html|htm|js|css)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>
</filesMatch>

这似乎是一个很好的解决方案,但是当我们需要缓存它和不应该缓存它时之间唯一真正的区别是 URL(preview.jsp 与 run.jsp),因此我们无法匹配它按文件类型划分,因为大多数文件都是相同的。

对于这种情况,有人有好的解决方案吗?

谢谢。

编辑:

Preview.jsp和run.jsp基本上是相同的,只是jsp和js处理不同。他们通过 iframe 读取相同的内容和媒体。例如,它们各自看起来像:

<%
//Some JSP
%>
/* HTML Headers, JS, ETC */
<iframe id="contentFrame" seamless="1" src="http://somedomain.com/template.html"></iframe>
/* End HTML */

preview.jsp 和 run.jsp 出现在同一目录中并使用所有相同的资源。我正在寻找一种解决方案,让 Preview.jsp 不缓存任何内容,而 run.jsp 来缓存内容。

服务器使用 Apache Tomcat 设置。

最佳答案

SetEnvIf 的组合和 Header可能会成功:

# Image, CSS and JavaScript requests normally contain the Referer header
# which tells apache which page is requesting the resource
# Use SetEnvIf directive to set a flag for internal uses

SetEnvIf Referer preview\.jsp force_no_cache

# Header directive optionally accepts env= argument
# If present, the directive is fired if the flag is set

Header unset ETag env=force_no_cache

# repeat for other headers

关于apache - htaccess mod_headers 用于无缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10078168/

相关文章:

java - 使用 websphere api 获取当前应用程序实例?

php - 实时服务器上的 Symfony2 MethodNotAllowedHttpException

css - SSI 包含虚拟 CSS 问题

jsp - Bootstrap 模式上的 Ckeditor 下拉问题(单击时立即打开和关闭)

java - 复制线程的 session

java - 根据db中存储的用户服务渲染jsp页面的不同部分

caching - 启用缓存后如何持续部署 Web 应用程序?

php - PHP 应用程序中缺少数据库连接错误

python - 如何在 Fedora 17 上将 FCGI 与 Python(和 Django)结合使用?

PHP mkdir 不工作——可能与 Mac 本地主机有关