5

I use Tomcat 7 on Windows XP.

  • I have a directory with static files (HTML, CSS, JS) in %TOMCATDIR%/webapps/myapplication.
  • They're accessible via localhost:8080/myapplication

When a change happens to a file in my server dir, it is not reflected:

  • modified files are returned (200 OK) the same as previously (tested with Fiddler; for sure not a browser cache issue - cleared cache, using different browsers etc.),
  • newly created files in that directory are not accessible (404).

The above happens no matter how many times I try to reload the file, or even add query string to it (img.jpg?timestamp=...).

In %TOMCATDIR%/conf/context.xml I've set various directives to disable server-side caching:

<?xml version='1.0' encoding='utf-8'?>
<Context antiResourceLocking="true" cachingAllowed="false" cacheMaxSize="1" cacheTTL="1">
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>

What is wrong?

jakub.g
  • 38,512
  • 12
  • 92
  • 130
  • See also http://serverfault.com/questions/40205/how-do-i-disable-tomcat-caching-im-having-weird-static-file-problems and http://stackoverflow.com/questions/3743136/how-to-disable-tomcat-caching – Didier L Sep 08 '14 at 14:58

3 Answers3

2

The solution seems to be remove antiResourceLocking="true".

If anyone's more knowledgable about the topic, or know how to workaround it other way, I'll be grateful.

jakub.g
  • 38,512
  • 12
  • 92
  • 130
  • 1
    Note that if you are uploading files into `webapps/myapplication`, you run the risk of Tomcat deleting all of them when you undeploy the webapp. You might want to look into the `aliases` feature of the `` element to "mount" directories outside of the deployment directory: these directories will not be deleted during an undeployment. – Christopher Schultz Jul 04 '12 at 20:27
  • I don't mean the WAR that is being extracted to `myapplication`, but the folder I've created myself. In that situation, it shouldn't be ever removed by Tomcat I guess, right? Anyway, I don't develop directly in this folder, I do it in some other place and Eclipse FileSync plugin synchronizes from dev folder to server folder on file save. However I'll try to take a look at what you've written. – jakub.g Jul 04 '12 at 21:29
  • I mean that Tomcat deletes deployment directories (like `webapps/myapp`) on undeploy. It will also follow symlinks (on filesystems that support such things) and delete all the files. If you use `aliases`, your files in the aliased paths will not be deleted during undeploy. – Christopher Schultz Jul 06 '12 at 01:43
  • +1, I had the same issue and this fixed it. I'm a bit surprised this isn't more documented. The documentation only says “Please note that setting this to true has some side effects, including the disabling of JSP reloading in a running server: see Bugzilla 37668.” http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Standard_Implementation – Didier L Sep 08 '14 at 14:57
  • I'm having this exact issue, but making my Context look exactly like the example above (minus the antiResourceLocking="true" of course) doesn't have any effect. Any ideas? – Walt D Feb 04 '15 at 01:02
  • I am facing same issue when using tomcat7, my context.xml has this : ` WEB-INF/web.xml ` and yet i face the problem. please suggest an idea. – Disera Mar 14 '16 at 07:34
0

Tomcat 8 - disable caching of static resources:

context.xml

     <Resources cachingAllowed="false"/>
Andre
  • 390
  • 3
  • 8
0

Finally the solution is to replace %TOMCATDIR%/conf/context.xml file content within :

<?xml version='1.0' encoding='utf-8'?>
<Context cachingAllowed="false" cacheMaxSize="1" cacheTTL="1">
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
dambo14
  • 31
  • 3