usertest
usertest

Reputation: 2262

putting jsf.js at the end of the body

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.

Upvotes: 2

Views: 900

Answers (2)

tandraschko
tandraschko

Reputation: 2346

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

Upvotes: 5

Selaron
Selaron

Reputation: 6184

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");

Upvotes: 2

Related Questions