问题
I want to create a way to update references to css files in jsf in an automated way (through ant, etc.) what is the common practice for this? are there any automated tools available already?
Basically I want to be able to deploy my war file and make sure that any changes the modified css files are downloaded by clients without them having to clear their cache. Thanks for the help!
回答1:
You can make use of JSF builtin resource library versioning. You'll only need to introduce a resource library in webapp's /resources
folder if not done yet. Then you can create a version subfolder with the pattern \d(_\d)*
. For example,
/resources/default/1_0/css/layout.css
Which you reference as follows:
<h:outputStylesheet library="default" name="css/layout.css" />
The library version is appended as 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, rename the 1_0
subfolder to 1_1
or something different (can be done by ant) and it'll be updated and the browser will be forced to download it instead of using the cached one.
The same applies to <h:outputScript>
and <h:graphicImage>
for JS and image resources.
来源:https://stackoverflow.com/questions/10591449/css-file-with-version-appending