Women in Technology

Hear us Roar

  Two Servlet Filters Every Web Application Should Have
Subject:   Also enable caching at the browser level
Date:   2003-11-24 02:08:08
From:   anonymous2
Make sure also to investigate caching at the browser level. It can really make an enormous difference to the user experience.

We use a servlet filter to add a
Cache-Control: public, max-age=3600
http header to all recurring static content (e.g. gifs, jpgs, style sheets, javascript etc).

In our case, this removed approx 75% of all hits to the server - and made the pages load much faster.

You may want to extend the filter to also handle the if-modified-since request header.

Full Threads Oldest First

Showing messages 1 through 1 of 1.

  • Also enable caching at the browser level
    2003-11-24 12:29:37  jfalkner [View]

    Good point. Here is a little bit of text and filter code for manipulating the Cache-Control HTTP header. The writeup also includes a link to the HTTP 1.1 spec section describing the Cache-Control filter.

    I don't think mixing code for client-side cache control and server-side caching is a good idea. Mostly because the logic gets a little messy, e.g. usually you don't want to server-side cache static resources such as images, but you almost always would want to try and have the client cache images. How do you go about deploying the same filter to do this well? Might as well split the functionality in to two simple filters.