简体   繁体   中英

Loading order of jQuery Magento

I have the following in local.xml.

<reference name="head">
    <block type="core/text" name="google.cdn.jquery">
        <action method="setText">
            <text><![CDATA[<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script><script type="text/javascript">jQuery.noConflict();</script>]]>
            </text>
        </action>
    </block>
        <action method="addJs"><script>smartwave/jquery/jquery-migrate-1.0.0.js</script></action>
        <action method="addJs"><script>smartwave/jquery/jquery-noconflict.js</script></action>

I'm needing that jQuery from the google repository to load first. But when the page loads there are many other jQuery dependent scripts loading that will break once I remove older versions of the library they are depending upon.

The Angular scripts are fine I understand but it's things such as image sliders etc. that I need that Google jQuery to load first. I've also put it on head.phtml for my theme as well and the same result.

Any tips on getting this to load earlier than it currently is loading?

If you want to force the load order of Javascript included with the addJs method, the easiest way is to supply a name using the tag, eg:

 <action method="addJs"> <!-- Loads second --> <script>vendor/jquery-1.6.2.min.js</script> <params><![CDATA[name="jquery2"]]></params> </action> <action method="addJs"> <!-- Loads first --> <script>vendor/jquery-1.8.2.min.js</script> <params><![CDATA[name="jquery1"]]></params> </action> 

Magento will load the Javascript files is ascending alphabetical order based on the name supplied.

In your case, though, it might be more fruitful to find out why the extensions and various jQuery files aren't playing nice with each other.

Let me know if you have any query

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM