2010-09-16 85 views
1

我已经通读了几个答案,并没有一个工作。我在应用程序的META-INF/context.xml中放入了一个缓存。Tomcat防止静态资源缓存

我已经在server.xml和context.xml中放了cachingAllowed ='false'。我也删除了我的工作/ [app]缓存,这就是我看到资源回来的情况。

JSP - 看起来不错!

请求URL:/loadconf.jsp

请求方法:GET

状态代码:200 OK

请求头

接受:/

的Referer: http://localhost/

User-Agent:Mozilla/5.0(Windows; U; Windows NT 6.1;的en-US)为AppleWebKit/534.3(KHTML,例如Gecko)铬/ 6.0.472.59 Safari浏览器/ 534.3

响应头

内容类型:应用/ JavaScript的;字符集= UTF-8

日期:星期四,2010 09月16日16点52分35秒GMT

服务器:Apache-狼/ 1.1

传输编码:分块

JS L - ooks坏

请求URL:yuiloader-DOM-event.js

请求方法:GET

状态代码:200 OK

请求头

接受:/

引用者:http://localhost/

User-Agent:Mozilla/5.0(Windows; U; Windows NT 6.1; AppleWebKit/534.3(KHTML,如Gecko)Chrome/6.0.472.59 Safari/534。3

响应头

接受-范围:字节

缓存控制:最大年龄= 15552000

的Content-Length:60327

的Content-Type :text/javascript

日期:2010年9月16日(星期四)16: 39:57 GMT

ETag的:W/“60327-1273012296000”

到期日:星期二,2011 16点39分57秒GMT

最后所3月15日加减:星期二,04五月2010 22点31分36秒GMT

服务器:Apache-狼/ 1.1

+0

我要你点@ BalusC的出色答卷这个 http://stackoverflow.com/questions/2156077/how-can-i-disable-tomcat-caching-completly/2163381#2163381 – JoseK 2010-09-17 06:37:29

+0

我需要为每个文件添加一个过滤器来做到这一点....为什么Tomcat甚至认为这些文件应该被缓存,为什么说它应该被缓存xxx长。没有指定这些参数。 – Drew 2010-09-20 16:49:16

回答

3

易于方法,使用Apache,如下所示:

# Configure Tomcat proxys 
<VirtualHost localhost:80> 

    ProxyPass/http://localhost:8080/ 
    ProxyPassReverse/http://localhost:8080/ 

    #for files that have no header 
    ExpiresDefault now 
    ExpiresByType text/javascript now 

    #overwrite the headers tomcat is foolishly trying to provide 
    Header set Cache-Control "max-age=0, must-revalidate" 
    Header set Expires "January 1, 1970" #this should be "now", but it wasn't working for me 

</VirtualHost> 

我的静态文件现在回来200响应。