File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Tomcat and the fly likes Does Tomcat cache CSS files? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Does Tomcat cache CSS files?" Watch "Does Tomcat cache CSS files?" New topic

Does Tomcat cache CSS files?

Tim Hagberg

Joined: Jan 29, 2010
Posts: 12
I have a personal Java-backed website I'm building with Tomcat, and I've run into an annoyance. After making some changes to a stylesheet, when accessing the website from a browser I was getting the old version of the css file. I assumed it was just the browser (Firefox) that was caching the file, but I've tried clearing the browser's cache and it has not helped. If I look at the file on the server or type the url of the css file in my browser, I see the updated version, but when examining it through Firebug I see the old version (and by looking at the rendered page it is obvious that it is using the old version). To rule out Firebug I have tried turning it off and closing/reopening Firefox and loading the page again, but that has not helped. Especially strange is that I tried changing the name of the css file (and obviously also changing link tag on the page as well) but this has not helped. At this point I am wondering if Tomcat's servlet container stores compiled JSPs somewhere, and if that is true perhaps it is storing linked stylesheets as well.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13036
Tomcat does nothing magic with CSS files, just serves them just like all other static resources.

Surely the caching is occuring somewhere else.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

To put it even more bluntly, Tomcat doesn't cache, period.

Is there maybe a caching proxy server between the client and Tomcat?

A trick that I use to get updated cache and CSS in Firefox is to instruct the browser to fetch the updated file directly. That is, I type the updated file's URL directly into the navigation bar so that it displays in a web page all its own. Sometimes I have to give it an extra kick by pressing the Refresh button (F5) once it's loaded to force an update, but that usually works. I can then generally go back and request the page that references the updated resource and expect it to work.

An IDE is no substitute for an Intelligent Developer.
Tim Hagberg

Joined: Jan 29, 2010
Posts: 12
I apologize for the late response. It turns out there was some malformed CSS that apparently Firefox was simply ignoring. I'm no expert on this, but I'm assuming CSS files must be stored somewhere on the DOM, and if that's the case, Firefox wasn't putting the malformed CSS on the DOM. That would explain why I was seeing the new CSS entries when putting in the full URL to the stylesheet in the address bar. Thank you both for your responses and advice.
I agree. Here's the link:
subject: Does Tomcat cache CSS files?
It's not a secret anymore!