title: How to disable caching of static assets like .css and .js in JSF2?
body: <p>I'm trying to set up a project to not cache static assets .css and .js.  We seem to be having some internal caching issues for some people and I'm hoping this clears it up.</p>
  
  <p>I have in place a phase listener, basically a slightly modified version of this <a href="http://turbomanage.wordpress.com/2006/08/08/disable-browser-caching-in-jsf/" rel="nofollow">http://turbomanage.wordpress.com/2006/08/08/disable-browser-caching-in-jsf/</a></p>
  
  <p>My class:</p>
  
  <pre><code>package com.ods.common.jsf.phaselistener;
  
  import javax.faces.context.FacesContext;
  import javax.faces.event.PhaseEvent;
  import javax.faces.event.PhaseId;
  import javax.faces.event.PhaseListener;
  import javax.servlet.http.HttpServletResponse;
  
  public class CacheControlPhaseListener implements PhaseListener
  {
  public PhaseId getPhaseId()
  {
      return PhaseId.RENDER_RESPONSE;
  }
  
  public void afterPhase(PhaseEvent event)
  {
  }
  
  public void beforePhase(PhaseEvent event)
  {
      FacesContext facesContext = event.getFacesContext();
      HttpServletResponse response = (HttpServletResponse) facesContext
              .getExternalContext().getResponse();
      response.setHeader("Cache-control", "no-cache"); // HTTP 1.1
      response.setHeader("Cache-control", "no-store"); // HTTP 1.1
      response.setHeader("Cache-control", "must-revalidate"); // HTTP 1.1
      // response.setHeader("Pragma","no-cache"); //HTTP 1.0
      response.setHeader("Allow", "GET"); // Allowing GET Method only
      response.setHeader("Allow", "POST");// Allowing POST Method only
      response.setDateHeader("Expires", -1); // prevent caching at the proxy server
  
              /*what I've added*/
      response.setHeader("Pragma", "no-cache");
      response.setHeader("Content-type", "x-javascript");
              //below are the content types I'm seeing for the css/js assets via Firebug
      response.setHeader("Content-type", "application/x-javascript");
      response.setHeader("Content-type", "text/css");
  }
  }
  </code></pre>
  
  <p>My addition to faces-config.xml:</p>
  
  <pre><code>&lt;lifecycle&gt;
      &lt;phase-listener id="nocache"&gt;com.ods.common.jsf.phaselistener.CacheControlPhaseListener&lt;/phase-listener&gt;
  &lt;/lifecycle&gt;
  </code></pre>
  
  <p>My .xhtml page is getting an expires header in the past:</p>
  
  <pre><code>Expires Thu, 01 Jan 1970 00:00:00 GMT
  </code></pre>
  
  <p>So this seems to be working somewhat...I'm assuming this date is from the Expires -1 (setting it to the unix epoch).</p>
  
  <p>As you can see, I've tried setting appropriate content-type headers for some javascript and css but the expire dates on those assets are a week into the future.</p>
  
  <p>Anyone have any ideas?  Also, I'm a front-end developer, not a back-end java guy.  I can mess around with Java, but I'm defintiely not a java developer.  This is my first job with JSF as well so as much as you can dumb down would be good :)</p>