2

I am trying out the UnmappedResourceHandler in OmniFaces, originally I had all my resources under a directory structure like:

WebContent
 |-- resources
 |    `-- default
 |         `-- 1_0
 |              |-- css
 |              |    `-- style.css
 |              |-- img
 |              |    `-- logo.png
 |              `-- js
 |                   `-- script.js

The UnmappedResourceHandler doesn't work with the versioning, instead this works:

WebContent
 |-- resources
 |    `-- default
 |        |-- css
 |        |    `-- style.css
 |        |-- img
 |        |    `-- logo.png
 |        `-- js
 |             `-- script.js

I haven't read anywhere that it doesn't work so I am wondering am I missing something?

thanks,

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Ross
  • 3,008
  • 1
  • 22
  • 27

1 Answers1

3

It's mentioned in the javadoc and showcase.

And the following CSS file reference (note: the library is not supported by the UnmappedResourceHandler! this is a technical limitation, just exclusively use name):

<h:outputStylesheet name="css/style.css" />

The technical limitation is that it's otherwise not possible to relatively reference resources from inside the CSS file. When using libraries, the path /default would be moved to query parameter ?ln=default and then the CSS file would be looking for relative image references in the wrong relative folder /resources/css instead of /resources/default/css.

You've 2 options:

  1. Manually append the version to the query string.

    <h:outputStylesheet name="default/css/style.css?#{app.version}" />
    

    You could even write another custom resource handler for that.

  2. Use the file name based versioning.

    WebContent
     |-- resources
     |    `-- default
     |        |-- css
     |        |    `-- style.css (this is a folder!)
     |        |         `-- 1_0.css
     |        |-- img
     |        |    `-- logo.png (this is a folder!)
     |        |         `-- 1_0.png
     |        `-- js
     |             `-- script.js (this is a folder!)
     |                  `-- 1_0.js
     :
    

    It's only uglier.

Regardless, feel free to just remove the /default folder in the end.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • sorry, I had read that but didn't know that the library attribute was related to the version number – Ross Jan 09 '15 at 16:29