【问题标题】:Loading order of jQuery MagentojQuery Magento 的加载顺序
【发布时间】:2015-08-14 03:59:06
【问题描述】:

我在 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>

我需要先加载来自 google 存储库的 jQuery。但是,当页面加载时,一旦我删除了它们所依赖的旧版本的库,就会加载许多其他 jQuery 相关脚本,这些脚本会中断。

我理解 Angular 脚本很好,但我需要首先加载 Google jQuery 等图像滑块等内容。我也将它放在我的主题的 head.phtml 上,结果相同。

有什么提示可以让它在当前加载之前加载?

【问题讨论】:

    标签: jquery magento


    【解决方案1】:

    如果你想强制 addJs 方法中包含的 Javascript 的加载顺序,最简单的方法是使用标签提供名称,例如:

    <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 将根据提供的名称按字母升序加载 Javascript 文件。

    不过,在您的情况下,找出扩展和各种 jQuery 文件不能相互配合的原因可能会更有成效。

    如果您有任何疑问,请告诉我

    谢谢

    【讨论】:

    • 但是使用它会假设我也将参数添加到所有其他 js 调用中?
    猜你喜欢
    • 1970-01-01
    • 2016-09-27
    • 1970-01-01
    • 2012-09-18
    • 1970-01-01
    • 2014-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多