How to implement no caching on JSF pages

Currently there are 2 ways I know that can do this.

1.) By implementing Filter and manually overriding the cache controls. See code below (note: not my original I found this somewhere else long time ago):
@WebFilter(servletNames = { "Faces Servlet" })
public class NoCacheFilter implements Filter {

 public void doFilter(ServletRequest req, ServletResponse res,
   FilterChain chain) throws IOException, ServletException {
  HttpServletRequest request = (HttpServletRequest) req;
  HttpServletResponse response = (HttpServletResponse) res;

  if (!request.getRequestURI().startsWith(
    request.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)) {
   // Skip JSF resources (CSS/JS/Images/etc)
     "no-cache, no-store, must-revalidate"); // HTTP 1.1.
   response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
   response.setDateHeader("Expires", 0); // Proxies.

  chain.doFilter(req, res);

 public void init(FilterConfig filterConfig) throws ServletException {


 public void destroy() {



2.) The one I preferred, using omnifaces' CacheControlFilter. More information available at: To use just need to add the filter and integrate with facesServlet.

 <servlet-name>Faces Servlet</servlet-name>
How to implement no caching on JSF pages How to implement no caching on JSF pages Reviewed by Edward Legaspi on Friday, January 09, 2015 Rating: 5

No comments:

Powered by Blogger.