本文介绍了htaccess的mod_headers中无缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个应用程序,允许用户添加/编辑/替换/删除内容(文字,图片,SWF文件,MP3音乐等)。我们希望管理员总是使用无缓存头拥有最新更新的文件,并在用户运行应用程序,一切变得/使用缓存。

We have an application that allows users to add/edit/replace/delete content (text, images, swfs, mp3s, etc). We want the admins to always have the latest updated files by using a no-cache header and when a user runs the application, everything gets/uses the cache.

我已经调查解决方案,并使用HTML meta标签等已经尝试:

I have looked into solutions and have tried using html meta tags like:

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

但是,这似乎并没有得到很好的解决,因为这发生在创建头后不改变媒体(图像,SWF文件,MP3音乐等)的头。

But that doesn't seem to be a good solution as this happens after the headers are created and doesn't change the media (images, swfs, mp3s, etc) headers.

我想使用Apache设置页眉和过这个code来抓的:

I wanted to use apache to set the headers and came across this code for 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>

这似乎是一个很好的解决方案,当我们需要它的缓存之间但是唯一真正的区别,当它不应该被cached是URL(preview.jsp VS run.jsp),所以我们可以' ŧ按文件类型匹配它的大多数文件都是一样的。

This seems to be a great solution, however the only real difference between when we need it cached and when it shouldn't be cached is the URL (preview.jsp vs run.jsp), so we can't match it by file type as most files are the same.

有没有人有这种类型的情况下很好的解决方案?

Does anyone have a good solution for this type of scenario?

感谢。

编辑:

preview.jsp和run.jsp基本上是相同的只与不同的JSP和JS处理。他们通过iframe相同的内容和媒体读取。例如,他们每个如下:

Preview.jsp and run.jsp basically are the same only with different jsp and js processing. They read in the same content and media through an iframe. For example, they each look like:

<%
//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缓存的东西。

preview.jsp and run.jsp appear in the same directory and use all the same resources. I am looking for a solution to have preview.jsp not to cache anything and run.jsp to cache things.

服务器所用的Apache Tomcat。

Server is setup with Apache Tomcat.

推荐答案

的和的可能做的伎俩:

A combination of SetEnvIf and Header might do the trick:

# 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

这篇关于htaccess的mod_headers中无缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 19:05