Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF 2 resources with CDN?

Tags:

jsf-2

As i understand it, the needs for JSF 2 resources is to help organizing resources directories, and add some versioning and localization.

But is it possible to combine this feature with a CDN ? I've never used CDN before, but it looks good, and would like to hear your ideas about it and possible combinations with JSF 2 resources, although i dont think it's likely.

like image 832
Albert Gan Avatar asked Nov 09 '11 16:11

Albert Gan


1 Answers

This is not possible with <h:outputScript> and <h:outputStylesheet> yet, as they can only point to webapp's own resources, not to an external URL. This feature has already been requested to the JSF guys. See also JSF spec issue 598. Right now it's scheduled for 2.2, but I don't expect it to be already implemented then as it's currently at 0 votes.

Until then, you'd need to specify them yourself using plain HTML <link> and <script> in <h:head>. You could make it a template definition if necessary, surely when you'd like to define them on a per-view basis.

<h:head>
    ...
    <ui:insert name="resources" />
</h:head>

and

<ui:define name="resources">
    <link rel="stylesheet" type="text/css" src="http://.../foo.css" />
    <script type="text/javascript" src="http://.../foo.js"></script>
</ui:define>

Update the JSF utility library OmniFaces has since version 1.2 a CDNResourceHandler available which could be used to automatically replace JSF resources by CDN resources when running in production stage. See also the CDNResourceHandler showcase page.

like image 159
BalusC Avatar answered Oct 03 '22 01:10

BalusC