JSF2 Static resource caching

前端 未结 1 1865
谎友^
谎友^ 2020-12-17 05:52

Glassfish 3.1.2, Mojarra 2.1.6, SSL activated

I have an question about static resource caching. I´ve read some posts about this but I´m not sure which options we sho

相关标签:
1条回答
  • 2020-12-17 06:28

    You only need to set Cache-Control. The Expires and Last-Modified are already set by default ResourceHandler (and would override the values set by your filter). The Last-Modified must represent the last modified timestamp of the resource in question. You can obtain it by servletContext.getResource(path).openConnection().getLastModified(). But you don't need to set it here anyway. Just let ResourceHandler handle.

    As to versioning, just use resource libraries rightly. You can put a version folder matching regex pattern \d+(_\d+)* in the library folder and the ResourceHandler will serve the newest.

    E.g.

    /resources/libraryname/1_0/js/file.js
    /resources/libraryname/1_1/js/file.js
    /resources/libraryname/1_2/js/file.js
    

    The following will then get the one from 1_2:

    <h:outputScript library="libraryname" name="js/file.js" />
    
    0 讨论(0)
提交回复
热议问题