1

I'm using Magento 1.5 (CE) and I'm slowly getting my head around it (how confusing is this piece of software?).

I want to add a js file to all my pages, but I'm not sure what i need to edit. I have created a file called app.js located in /skin/frontend/default/blank/js how do i add this file to all my templates?

newb
  • 11
  • 1
  • 1
    duplicated: http://stackoverflow.com/questions/4654822/how-to-add-adding-external-javascript-in-magento?answertab=oldest#tab-top – OSdave Jun 23 '11 at 11:34
  • What xml layout file is being referenced in the first block? – dotty Jun 23 '11 at 11:46

1 Answers1

3

Create a file local.xml in your theme's layout directory, and add the following block:

<default>
    <reference name="head">
        <action method="addJs">     
            <script>app.js</script>                         
        </action> 
    </reference>
</default>

Another common, related request is to allow this JS to be turned off conditionally. Magento supports this as well:

<default>
    <reference name="head">
        <action method="addJs" ifconfig="yourmodule/someconfig/boolfield">      
            <script>app.js</script>                         
        </action> 
    </reference>
</default>

Hope that helps!

Thanks, Joe

Joe Mastey
  • 26,809
  • 13
  • 80
  • 104
  • That's how it's done, only issue I have is that most javascript should be added in the footer, not the head, to improve page rendering speed. – Chaoley Jun 24 '11 at 09:26