White screen is not what your website's visitor came to see. If white screens is being showed long enough he/she may leave for other website.
I will use default Magento 220.127.116.11 installation to show case how to move js to the footer.
<core_block_abstract_to_html_after> <observers> <module_html_filter> <class>module/observer</class> <method>filterHtml</method> </module_html_filter> </observers> </core_block_abstract_to_html_after>
inside filterHtml method we filter html code:
then on controller_action_layout_load_before event we append our js:
$layout = $observer->getEvent()->getLayout()->getUpdate(); $layout->addHandle('goivvy_deferjs_custom_handle_inline');
First we create uphead block:
<block type="page/html_head" name="uphead" as="uphead" template="page/html/uphead.phtml"/>
uphead will be put in place of head block and will contain above-the-fold CSS.
Second we replace head with uphead and move head to the bottom in every *columns template (2columns-left, 2columns-right, 3columns etc).
<head> <?php if(Mage::helper('module')->isEnabled()):?> <?php echo $this->getChildHtml('uphead') ?> <?php else:?> <?php echo $this->getChildHtml('head') ?> <?php endif;?> </head>
<?php echo $this->getAbsoluteFooter() ?> <?php if(Mage::helper('goivvy_deferjs')->isEnabled()):?> <?php echo $this->getChildHtml('head') ?> <?php endif;?> </body> </html>
We don't put it in footer as footer is cached. Js might differ from page to page.
Once it is all ready Google PageSpeed Score goes up:
If you find this post interesting do not hesitate to sign up for our newsletter and join the 650 people who receive Magento news, tips and tricks regularly.