1
votes

My JEE6/JSF/primefaces application is available through https (two-way ssl: both server and user certificate required). I want browsers to cache resources files, so all resources are served with headers: "Cache-Control:public, max-age=2592000" and "Expires:Fri, 19 Dec 2014 07:46:27 GMT"(now+1 month). But still, both recent FF and IE request all js/css/png files on every page and after every refresh (F5). Below are my request and response headers. What am I doing wrong?

Request:            GET /javax.faces.resource/primefaces.css.jsf?ln=primefaces HTTP/1.1
Accept:         text/css, */*
Referer:            https://xxxxx.yy/zz/abc.jsf?type=1
Accept-Language:    en-US
User-Agent:     Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
Accept-Encoding:    gzip, deflate
Host:           xxxxx.yy
DNT:                1
Connection:     Keep-Alive
Cookie:         ServerID=1845; JSESSIONID=Wmsmxxx!-1754822933

Response:           HTTP/1.1 200 OK
Date:               Wed, 19 Nov 2014 07:37:49 GMT
Server:             Apache
Cache-Control:      public, max-age=2592000
Pragma:             public
Expires:            Fri, 19 Dec 2014 07:46:27 GMT
Last-Modified:      Tue, 13 Nov 2012 10:02:34 GMT
X-Powered-By:       Servlet/3.0 JSP/2.2
X-Powered-By:       JSF/2.0
Keep-Alive:         timeout=15, max=100
Content-Language:   en
Connection:         Keep-Alive
Transfer-Encoding:  chunked
Content-Type:       text/css
1

1 Answers

0
votes

It will depend on what type of requests have you enabled cache for.

Check the following two places to see what gets included in caching Your URL patten must match the requests coming through for the static content.

<filter-mapping>
    <filter-name>cache</filter-name>
    <url-pattern>*.xhtml</url-pattern>
</filter-mapping>

The second place would be in the cache filter itself. e.g. if you have your own cache filter, specify correct type of static content. If you are using out of the box implementation, then i suppose web.xml would take that as argument.

if (uri.contains(".js") || uri.contains(".css") || uri.contains(".svg") || uri.contains(".gif")
                || uri.contains(".woff") || uri.contains(".png")) {
            httpResponse.setHeader("Cache-Control", "max-age=" + maxAge);
        }

Here are the details of I have done this:
https://stackoverflow.com/a/35567540/5076414.
Hope this helps.