3

The JS file extra.js is included as follows:

<h:outputScript library="js" name="extra.js"  />

I am facing issue of browser caching. Many times, I will not get the updated copy.

In plain HTML, we used to append version number or random number with JS URL like:

<script type="text/javascript" src="http://yyy.zzzz.net/js/tryjs?v=1234"></script>
where v is the version number.

Is there any way to add some version number to the generated resource URL in h:outputScript?

4

1 回答 1

5

您可以执行以下操作之一

管理其中一个 bean 中的版本号#{myBean.myVersion}并将其附加到您的 js 文件中h:outputScript

像这样:

<h:outputScript library="js" name="extra.js?#{myBean.myVersion}/>

或重命名您的 js 文件以将其#{myBean.myVersion}作为其名称的一部分,如下所示

<h:outputScript library="js" name="extra.#{myBean.myVersion}.js/>

您也可以看看这个:JSF 2.0 中的资源(库)

于 2013-05-29T07:25:55.953 回答