About Cache-Control, Tomcat filters and browsers...

Discussion in 'Java' started by ENRIQUE, Apr 17, 2007.

  1. ENRIQUE

    ENRIQUE Guest

    Hi,

    Since tomcat doesn't provide any hint about cache policies for
    images, javascripts and other static files I created a filter for
    those files that read like:

    public class filterCacheControl implements Filter {
    ...
    public void doFilter(ServletRequest request, ServletResponse
    response, FilterChain chain) throws IOException, ServletException {
    ((HttpServletResponse)response).addHeader("Expires", "Thu, 1 Jan
    2099 23:59:59 GMT");
    ((HttpServletResponse)response).addHeader("Cache-Control", "max-
    age=600");
    ((HttpServletResponse)response).addHeader("Last-Modified", "Thu, 1
    Jan 1970 00:00:00 GMT");
    chain.doFilter(request, response);
    }
    ...
    }

    The filter works as expected and add the Cache-Control to the HTTP
    header.

    The problem is that the browser "neglects" it and tries to reload the
    files once and once again. The network capture shows next HTTP
    conversation:

    GET /src/event/common.js HTTP/1.1 <-- Browser request

    Host: osiris:8080

    User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.3) Gecko/
    20070310 Iceweasel/2.0.0.3 (Debian-2.0.0.3-2)

    Accept: text/xml,application/xml,application/xhtml+xml,text/
    html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5

    Accept-Language: es,en;q=0.7,en-us;q=0.3

    Accept-Encoding: gzip,deflate

    Accept-Charset: UTF-8,*

    Keep-Alive: 300

    Connection: keep-alive

    Referer:
    http://osiris:8080/Controller?formA...art=true&formStep=2&formHora1=16&formHora2=18

    Cookie: JSESSIONID=ED268E69F6A0993BB152ABDC7545A433

    If-Modified-Since: Tue, 17 Apr 2007 09:50:44 GMT

    If-None-Match: W/"28830-1176803444000"

    Cache-Control: max-age=0



    HTTP/1.1 304 Not Modified <-- Tomcat response

    Expires: Thu, 1 Jan 2099 23:59:59 GMT

    Cache-Control: max-age=600

    Last-Modified: Thu, 1 Jan 1970 00:00:00 GMT

    Date: Tue, 17 Apr 2007 15:30:14 GMT

    Server: Apache-Coyote/1.1



    a few seconds later:

    GET /src/event/common.js HTTP/1.1 <-- Why????? The browser already
    knew the common.js expires on 2099, the Cache-Control has a max-age of
    600 seconds, and it wasn't modifyied since 1970.

    .....

    Thanks in advance for any help, hint or link!!!
    ENRIQUE, Apr 17, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rjweytens
    Replies:
    0
    Views:
    436
    rjweytens
    Jun 30, 2004
  2. rjweytens
    Replies:
    0
    Views:
    3,395
    rjweytens
    Jun 30, 2004
  3. John Smith

    Tomcat and filters

    John Smith, Oct 20, 2005, in forum: Java
    Replies:
    0
    Views:
    355
    John Smith
    Oct 20, 2005
  4. Replies:
    0
    Views:
    454
  5. Dieter Vanderelst

    using the Filters DLL (image filters)

    Dieter Vanderelst, Feb 15, 2006, in forum: Python
    Replies:
    1
    Views:
    401
    Michele Petrazzo
    Feb 15, 2006
Loading...

Share This Page