Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I got an Apache Tomcat 7 server. If I change a file on the server (for example stylesheet, javascript file or any plain/text file), for example using vim. Then if I go to the file in an internet browser, and press F5 a few times till I see the actual change, I have to wait (while pressing F5 every 500 ms) a few seconds (~3 seconds) before I see what I just changed.

Thus in short: if a file is changed on the server, I see it ~3 seconds later client side. So somewhere there has to be a cache, probably server side since I use F5 which should discard client side cache. So how can I setup a directory on my Apache Tomcat server so that it will not cache files?

I want to do this because I created a simple Ajax/Servlet based website to chat. But after typing a message, it will appear ~3 secs later. I know this can be way faster, because I have done it before on a PHP free webhost server.

share|improve this question
up vote 3 down vote accepted

Tomcat caches static content with a TTL of 5 secs by default. If you want to change that see Specifically you want cacheTTL, cachingAllowed and maybe cacheMaxSize and cacheObjectMaxSize.

share|improve this answer

Not sure how Tomcat adds the no cache to everything. The easy way to control the headers yourself is to write and configure a generic header filter in web.xml as follows:

=== web.xml ===

NoCache x.y.z.filters.ResponseHeaderFilter

Cache-Control no-cache, must-revalidate


Cache-Control max-age=604800, public

NoCache /*.do

CacheForWeek /images/*

CacheForWeek /*.js

CacheForWeek /*.css

=== web.xml ===

share|improve this answer
Sorry if my question was not clear, but my question is about server side caching, not client side! – Yeti May 3 '12 at 15:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.