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

E

ENRIQUE

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!!!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top