开发者

How can I include a JS file with query string in <h:outputScript>?

In JSF page I use this code to include a JS file:

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

It works well, but I want to implement cache busting by adding a version parameter:

<h:outpu开发者_Python百科tScript library="js" name="reworkBase.js?version=1" />

But the JS file will not be found. I know it also works well if I use the <script type="text/javascript"> tag. But is there any way to implement with <h:outputScript> tag?


That's a bug in Mojarra. Their ScriptRenderer was as per issue 1212 fixed to support query strings. However, their fix was wrong for the case a library is specified. They used + instead of &amp; as query string parameter separator, which only results in 404's:

<script src="/context/javax.faces.resource/reworkBase.js.xhtml?ln=js+version=1">

It should have been:

<script src="/context/javax.faces.resource/reworkBase.js.xhtml?ln=js&amp;version=1">

I've reported this bug as issue 2168.

In the meanwhile your best bet is to just omit the library altogether, given the library name of js (which obviously stands for "JavaScript") you seem not to be interested in using configureable look'n'feel/scripting libraries at all.

<h:outputScript name="js/reworkBase.js?version=1" />

This will result in the right URL.

<script src="/context/javax.faces.resource/js/reworkBase.js.xhtml?version=1">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜