css file with version appending

久未见 提交于 2019-12-11 08:20:09

问题


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&amp;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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!