2

I have a Java EE 8 web application deployed. it uses JSF 2.3 I test it with google PageSpeed Insights. and a recommendation says:

Eliminate render-blocking resources

…font/fonts-min.css.xhtml?ln=custom(**.com)
…fullcalendar/fullcalendar.bundle-min.css.xhtml?ln=vendors(**.com)
…base/vendors.bundle-min.css.xhtml?ln=vendors(**.com)
…base/style.bundle-min.css.xhtml?ln=demo(**.com)
…fix/poppins.css.xhtml?ln=custom(**.com)
/javax.faces.resource/jsf.js.xhtml?ln=javax.faces(**.com)

since jsf.js is added by default by the JSF framework. is there a solution so that I make it load at the end of the body next to other javascripts. And if there is, would that be good idea?

Thanks.

usertest
  • 2,140
  • 4
  • 32
  • 51
  • 1
    Keep in mind that moving some css to the end might make rendering not specifically better sing the css and js is needed for rendering. And tge jsf.js file is loaded once and for the rest cached (if your server is configured correctly, so the optimization might be limited – Kukeltje Dec 04 '18 at 12:12
  • Not really an answer, but you could have a look at http://showcase.omnifaces.org/resourcehandlers/CombinedResourceHandler – Jasper de Vries Dec 04 '18 at 12:42

2 Answers2

5

If you use PrimeFaces, you could activate the "MOVE_SCRIPTS_TO_BOTTOM" feature via context-param.

This moves all script includes (script src="...") to the bottom and it also merges all inline scripts (...) to a single inline script.

This is really a great performance boost.

See: https://github.com/primefaces/primefaces/issues/2888

tandraschko
  • 2,291
  • 13
  • 13
2

It is possible to place the script to the end of the body using the target="body" attribute:

<h:head>
    <h:outputScript name="jsf.js" library="javax.faces" target="body"/>
</h:head>

But as Kukeltje notes, keep in mind that this might have side effects and the optimization gain may be limited to first request.

The reference implementation (mojarra) explicitly adds this script to the <head> element which might have good reasons:

com.sun.faces.renderkit.RenderKitUtils.installJsfJsIfNecessary(FacesContext):

context.getViewRoot().addComponentResource(context, createJsfJs(), "head");
Selaron
  • 6,105
  • 4
  • 31
  • 39
  • I'm aware of target="body" but not the value of library, So I guess there is no need to move it then. – usertest Dec 05 '18 at 08:53