All blog posts, code samples and downloads licensed under Apache License 2.0.
Close

Loading CDN framework resources

Oliver Busse on 06/23/2014 11:48:54 PM CEDT, filed under XSP XML Theme 

When using an external framework e.g. like Fontawesome you might wanrto use a CDN (content delivery network) instead of importing all the stuff into your application. Ok, this needs internet connectivity but, hey, you should have that already, right?

Using a theme may come in handy, too. But there is one problem computing the right scheme for the URL (which is the part that says "http" or "https"). As the value for the "href" attribute of a CSS resource entry cannot be computed you may want to switch to the following workaround: you just have to compute the "rendered" property of the resource entry depending on if you use http or https:

<!-- FontAwesome -->
	<resource rendered="#{javascript:context.getUrl().getScheme().equals('http')}">
		<content-type>text/css</content-type>
		<href>http://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css</href>
	</resource>
	<resource rendered="#{javascript:context.getUrl().getScheme().equals('https')}">
		<content-type>text/css</content-type>
		<href>https://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css</href>
	</resource>

The code above shows how to bind the Fontawesome CSS for your application depending on what scheme do you use for your application on your own environment.


Tagged with css xpages xsp theme