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?

2
  • 1
    duplicated: stackoverflow.com/questions/4654822/… Commented Jun 23, 2011 at 11:34
  • What xml layout file is being referenced in the first block? Commented Jun 23, 2011 at 11:46

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.