I would like to use the OmniFaces CombinedResourceHandler
to stream resources in one go.
I registered it in faces-config.xml
without any additional configuration parameters as described in CombinedResourceHandler documentation.
While it works fine with CSS resources, it does nothing with JavaScript resources. Here are my tests:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com /jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:o="http://omnifaces.org/ui">
<h:head>
<title>CombinedResourceHandlerTest</title>
<h:outputStylesheet name="css/bootstrap-3.3.5/bootstrap.css"/>
<h:outputStylesheet name="css/main.css" />
<h:outputScript name="js/jquery/jquery.min.js"/>
<h:outputScript name="js/bootstrap-3.3.5/bootstrap.min.js"/>
</h:head>
<h:body>
<f:view>
<h2>CombinedResourceHandlerTest</h2>
</f:view>
</h:body>
Output:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="j_idt2">
<title>CombinedResourceHandlerTest</title>
<script type="text/javascript" src="/testApp/javax.faces.resource/js/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/testApp/javax.faces.resource/js/bootstrap-3.3.5/bootstrap.min.js"></script>
<link type="text/css" rel="stylesheet" href="/testApp/javax.faces.resource/eNpLLi7WT8rPLykuKUos0DXWM9YzRfD1kouLa4BYPzcxMw_EAQCLpxEP.css?ln=omnifaces.combined&v=1480321351184">
</head>
Tried with attribute target="head":
<h:head>
<h:outputScript name="js/jquery/jquery.min.js" target="head"/>
</h:head>
...
Output: (scripts are completly missing):
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="j_idt2">
<title>CombinedResourceHandlerTest</title>
<link type="text/css" rel="stylesheet" href="/testApp/javax.faces.resource/eNpLLi7WT8rPLykuKUos0DXWM9YzRfD1kouLa4BYPzcxMw_EAQCLpxEP.css?ln=omnifaces.combined&v=1480321351184">
</head>
...
</html>
The scripts are also missing when i move them on the top of the body:
<h:body>
<h:outputScript name="js/jquery/jquery.min.js" target="head"/>
....
</h:body>
After a look into the source i also tried with
<o:deferredScript name="js/jquery/jquery.min.js"/>
After inspecting the output for this case, I saw that the combinend script only contains the first script in order and the console shows "ReferenceError: OmniFaces is not defined":
<body>
<script type="text/javascript">OmniFaces.DeferredScript.add('/testApp/javax.faces.resource/eNpLL81JLE7OsMoq1s8qLE0tqoRSermZeXpZxQDDagwa.js?ln=omnifaces.combined&v=0');</script>
</body>
And I noticed, that even jsf.js
is not included when having the CombinedResourceHandler
active. the browser console tells "mojarra is not defined".
What am I doing wrong? Thanks in advance!
My environment is: Mojarra 2.2.12, Omnifaces 2.5.1, Tomcat 8.
I reproduced a very similar issue last weekend. The cause boiled down to that Mojarra was initialized twice on a Tomcat 8 server and thus corrupted the one and other. You can confirm this by looking at the server log and notice that among others Mojarra version, OmniFaces version and PrimeFaces version are logged twice.
Please doubleverify if you have only one Mojarra instance and that you do not have the
ConfigureListener
entry inweb.xml
like below, as it's by default autoregistered already.See also: