Setting caching headers issue

UI Components for JSF
Post Reply
User avatar
MISS_DUKE
Posts: 273
Joined: 08 Aug 2010, 05:52

30 Dec 2010, 12:47

I use a Servlet filter to set HTTP headers which are responsible for caching static resources.

The filter annotation as follows:

Code: Select all

@WebFilter(filterName = "CashingServlet", urlPatterns = {
    //js files
    "*.js",
    //css files
    "*.css",
    //image files
    "*.png",
    "*.jpg",
    "*.gif",
    "*.ico"
}, dispatcherTypes = {DispatcherType.FORWARD, DispatcherType.ERROR, DispatcherType.REQUEST, DispatcherType.INCLUDE})
Codes setting the headers as follows:

Code: Select all

HttpServletResponse res = (HttpServletResponse) response;
        Calendar inOneMonth = Calendar.getInstance();
        inOneMonth.add(Calendar.MONTH, 1);
        res.setHeader("Cache-Control", "max-age=25920000, private");//300 days
              res.setDateHeader("Expires", inOneMonth.getTimeInMillis());//Expires does not work (header not set)
        
The response headers of the real output as follows: (data taken from Firebug, considering "utilities.js" as an example resource. But all static resources having similar response headers)

Code: Select all

X-Powered-By	Servlet/3.0, JSF/2.0
Server	GlassFish Server Open Source Edition 3.0.1
Cache-Control	max-age=25920000, private
Expires	Thu, 30 Dec 2010 09:39:47 GMT
Last-Modified	Thu, 30 Dec 2010 00:15:14 GMT
Etag	W/"124338-1293668114000"
Content-Type	text/javascript
Content-Encoding	gzip
Vary	Accept-Encoding
Date	Thu, 30 Dec 2010 09:29:42 GMT
The "Expires" header not as expected. What am I missing?

(The "Expires" header set the expiry date in just 10 minutes, but it should be 1 month according to the Servlet filter codes)
JSF implementation: Mojarra V2.1.7
JSF component library: Primefaces V3.1.1
Server: GlassFish Open Source Edition V3.1.1 (build 12)

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 67 guests