5

I am trying to put versioning around the resources in an application.

If I do like this resources/js/1_0_0/mainscript.js

It does not work. It says RESOURCE_NOT_FOUND

but when I do like this

resources/js/mainscript.js/1_0_0.js

It works. I do not like the way it is organized in the second way. First one looks cool. Any Idea?

I am using Tomcat 7.0, JSF 2.0.9

Update: I was checking primefaces-2-2.1.jar. Since when I checked the page source, I saw this /javax.faces.resource/jquery/jquery.js.xhtml?ln=primefaces&v=2.2.1">

Then I looked at META-INF/resources/primefaces/jquery/jquery.js

They did not have any versioning in there but how did it append v=2.2.1 in the head

Ravi Kadaboina
  • 8,494
  • 3
  • 30
  • 42

1 Answers1

11

If I do like this resources/js/1_0_0/mainscript.js

It does not work. It says RESOURCE_NOT_FOUND

This will work if you specify js as library name.

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

However, this is not the proper usage of a resource library. Rather introduce one.

resources/default/1_0_0/js/mainscript.js

Then you can specify it as follows:

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

They did not have any versioning in there but how did it append v=2.2.1 in the head

It's done by PrimeResource which kicks in on resource requests with ln=primefaces parameter. Its getRequestPath() has the following implementation:

@Override
public String getRequestPath() {
    return super.getRequestPath() + "&amp;v=" + Constants.VERSION;
}

Where Constants is the PrimeFaces specific constants file which is updated with every PF version.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I got it, I messed up the path previously I had something like this resources/js/default/mainscript.js. Then I changed it to resources/js/default/1_0_0/mainscript.js and referring it to like this which did not work. Upon seeing your answer I changed it to resources/js/1_0_0/default/mainscript.js and it worked. Thank you!! And this is same as using this right? Just the library names swapped. – Ravi Kadaboina Mar 29 '12 at 18:29
  • The library must represent a "theme"/"module", not the "content type". Using `library="js"`, `library="css"`, etc is a smell and indicates misunderstanding of the meaning of the `library` attribute. – BalusC Mar 29 '12 at 18:37
  • Note that primefaces removed resource versioning in v3.3 due to performances issues in mojarra -- see [primefaces issue#3705](https://code.google.com/p/primefaces/issues/detail?id=3705) and [mojarra issue#2494](https://java.net/jira/browse/JAVASERVERFACES-2494) – codeturner May 14 '13 at 15:35
  • Does the highest-version pickup only work for resources in a war? I tried putting the resources in a jar's META-INF/resources/library/1_0_0/... folder and placed that jar in my WEB-INF/lib but it didn't work. Moving the resources from the jar to the war worked. Also, putting the version as part of the name and keeping the resources in the jar worked too. – Xavier Dury Nov 14 '17 at 18:31