jQuery in Action, 2nd edition*
The moose likes Performance and the fly likes Caching static files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Caching static files" Watch "Caching static files" New topic
Author

Caching static files

Pankaj Kumarkk
Ranch Hand

Joined: Apr 17, 2011
Posts: 108
I have a tomcat based web application. I am using JSP as the presentatio tier. I have a lot of static files(html, png, jpg) files which do not change in the lifetime of server instance. I want to know how I can improve loading of these files on the client(browser)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

In normal circumstances the browser will cache static files without being told to. Is this not happening in your configuration?
Pankaj Kumarkk
Ranch Hand

Joined: Apr 17, 2011
Posts: 108
I think this is not happening. Let me know how I can configure the browser.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

I have no idea. (Besides, you didn't say which browser.) Browsers come configured to cache content by default, so you must already have done something to your browser to stop it from doing that. Whatever it was, undo it.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41874
    
  63
Also make sure that during a deployment the timestamp on files that have not changed stays the same as before. That helps by causing a 304 response to be returned for files that have not changed since the browser last requested them.


Ping & DNS - my free Android networking tools app
Pankaj Kumarkk
Ranch Hand

Joined: Apr 17, 2011
Posts: 108
Thanks for the suggestion. Will look and reset the browser settings.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4658
    
    5

One obvious solution is to not reference the static files through your JSP/servlet. Put them on a simple web server, and include the URL. Let the browser and Apache (or whatever you use) do the optimization.

Some high volume sites go so far as to have a separate static host and DNS entry, something like "http://images.coderanch.com" that used for all images.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Caching static files