How to disable caching of static assets like .css and .js in JSF2?

后端 未结 1 1498
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-30 17:49

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

1条回答
  •  梦毁少年i
    2020-12-30 18:26

    With the setHeader() you're overridding any previously set header. Rather use addHeader() instead, or just put all values commaseparated as the header value. Here's the complete set:

    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
    response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
    response.setDateHeader("Expires", 0); // Proxies.
    

    Your another mistake is that a PhaseListener isn't the best place for this. It's only invoked on JSF page requests, not on static resource requests which are independently invoked by the webbrowser. In other words, only the JSF page itself has caching disabled, but all

    with in faces-config.xml

    
        startup
        java.util.Date
        application
    
    

    This example would force the browser to reload the assets whenever the server has restarted.

    0 讨论(0)
提交回复
热议问题