If you want to take advantage of JSF's built-in resource library versioning feature, the first step is to create a resource library in your webapp's /resources
folder if you haven't already done so. Once that's set up, you can add a version subfolder using the pattern \d(_\d)*
. For example,
/resources/default/1_0/css/layout.css
To reference this resource, you would use:
<h:outputStylesheet library="default" name="css/layout.css" />
The library version will be appended as a v
parameter in the query string of the generated <link>
element.
<link type="text/css" rel="stylesheet" href="/contextname/javax.faces.resource/css/layout.js.xhtml?ln=default&v=1_0" />
When you need to deploy an update, simply rename the subfolder from 1_0
to 1_1
or any other version (you can automate this process with ant). This way, the updated resource will be downloaded by the browser instead of using the cached one.
This versioning technique also applies to <h:outputScript>
and <h:graphicImage>
for JavaScript and image resources within JSF.