OmniFaces CDNResourceHandler could not find resources when not included locally

251 views Asked by At

I'm using OmniFaces CDNResourceHandler to point my resources to a CDN, instead of local files.

I added this line in my XHTML file: <h:outputStylesheet library="twitter-bootstrap" name="bootstrap.min.css" />

And my faces-config.xml have this line:

<context-param>
    <param-name>org.omnifaces.CDN_RESOURCE_HANDLER_URLS</param-name>
    <param-value>
        twitter-bootstrap:bootstrap.min.css=https://somehost/twitter-bootstrap/3.3.7/bootstrap.min.css
    </param-value>
</context-param>

And I'm getting this error when access the page:

Unable to find resource twitter-bootstrap, bootstrap.min.css

Note: When I access the file at https://somehost/twitter-bootstrap/bootstrap.min.css I can download the file properly.

I'm using Mojarra under Wildfly configured to Development stage.

The resource handler is properly configured at faces-config.xml file.

<application>
    <resource-handler>org.omnifaces.resourcehandler.CDNResourceHandler</resource-handler>
</application>

I did some tests, and I notice that the error doesn't occurs if I create an empty file bootstrap.min.css under WEBAPP_FOLDER/resources/twitter-bootstrap. If I delete the file, the errors occurs again.

Even I use CDN, do I need to keep resources locally?

1

There are 1 answers

3
BalusC On BEST ANSWER

The CDNResourceHandler is primarily intented to move auto-included JSF resources to a CDN, such as jsf.js file from <f:ajax>, or primefaces.js and jquery.js from PrimeFaces, or to automatically switch to a CDN when installed in production.

You don't need it in your case with a permanent CDN resource. Just use plain <link>.

<link rel="stylesheet" src="https://somehost/twitter-bootstrap/bootstrap.min.css" />

This is also explicitly mentioned in the CDNResourceHandler documentation.

For non-JSF resources, you can just keep using plain HTML <script> and <link> elements referring the external URL


Update: as you're not the first one who wondered about this, I've as per issue 122 bypassed this technical restriction for OmniFaces 2.6. In other words, you do not necessarily need a local resource anymore.