webtier@glassfish.java.net

Optimize page load duration

From: <webtier_at_javadesktop.org>
Date: Thu, 27 Aug 2009 06:17:16 PDT

Just an idea for (hopefully) upcoming JSF 2.1 ...

I digged a lot in the source solving the problem that inline javascript and onevent handlers on tags are not considered to be modern any more. Having google's best practises for website loading optimization (http://code.google.com/speed/articles/include-scripts-properly.html) in mind, all static javascript followed by inline javascript should be rendered right before body's closing tag and not in the head or in the middle of the page, because this slows down downloading of other resources (images, css, flash) significantly.

I had two solutions in mind, both of them not perfect:

1) All inline javascript and event binding is done at the bottom of the body in an inline javascript block. This could be done by rearranging inline js blocks like <h:outputScript target="body"> does and render the event binding block explicitly by traversing the view another time using a component vistor which only render the js binding code.

2) Render the page without any js. Instead register a document.ready listener which fire an ajax request that traverse the view like in 1. but returns the inline js and binding code as <eval> response.

Both solutions are not perfect at all. The first one still embeds js code in the html page, even all js is rendered in one position. The second one requires an additional request to be sent, which has to wait until the required resource jsf.js was loaded.

In addition we need to keep partial page rendering in mind. If we detach html elements and their event bindings we need to make sure that added elements during an ajax request will receive their bindings in an extra <eval> block.


Suggestions and other possible solutions to avoid inline javascript and event binding are welcome.

BR, Sven
[Message sent by forum member 'tzwoenn' (tzwoenn_at_gmx.de)]

http://forums.java.net/jive/thread.jspa?messageID=362145