4

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:outputScript 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?

1 Answer 1

2

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">
Sign up to request clarification or add additional context in comments.

4 Comments

I tried <h:outputScript name="js/myJsFile.js" />, and it results in <script src="/context/javax.faces.resource/js/myJsFile.js">. No .xhtml?version=1 part. What do I need to do for that part to show up?
Sorry, the example in my answer was bad, you should be adding ?version=1 to the name :) I edited the answer. The key point is to just omit the library.
@BheshG: Are you the questioner? It's a different user account?
Sorry. I am not. I just found it interesting so. Sorry if I confused you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.