How to use conditional stylesheets or javascript with JSF

Standard

A annoying part of JSF is that it will strip out all of your conditional statements. These conditional references are needed for IE bug fixes 99% of the time. The solution is a simple hack using the outputText component. This will treat the html entities as strings and convert them.

For example this outputText will render the html5shiv cdn.

<h:outputText
value="&lt;!--[if lte IE 8]&gt;
&lt;script src=&quot;//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv.min.js&quot;&gt;&lt;/script&gt;
&lt;![endif]--&gt;"
escape="false" />

Results

<!--[if lte IE 8]>
  <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv.min.js"></script>
<![endif]-->

Now once rendered the browser will be able to correctly interpret your conditional statements.