Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have put on my page.xml a new block for add my minify magento scripts to the bottom.

<block type="page/html_head" name="javascript" as="javascript" template="page/html/javascript.phtml">
   <action method="addJs"><script>scripts.js</script></action>
</block>

And in my template just before </body> :

<?php echo $this->getChildHtml('javascript') ?>

It's perfect and scripts.js load now to the bottom.

But I don't understand because when I load scripts.js to the bottom nothing works correctly on my frontend and if I move to the top it's perfect...

Thanks for your help.

share|improve this question
up vote 3 down vote accepted

Before a JavaScript function or method can be called, it must be declared. Magento has many such calls within the body and as such, those calls will be to "undefined" functions. The way around that is to not initialize anything until the DOM has loaded and the scripts have downloaded, but Magento was not built like that. As such, unless you make a lot of changes, the core JavaScript needs to remain in the head. That said, there are usually some scripts that you can remove from pages such as the home page. That will be a performance boost at least for first-time visitors.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.