Magento XML AddJs - 在src之前添加参数

时间:2015-04-23 10:15:48

标签: javascript xml magento cloudflare

在local.xml中,我需要添加此参数以防止Cloudflare Rocket Loader在特定脚本上运行。

<params>data-cfasync="false"</params>

我有这样的时间:

<action method="addItem"><type>skin_js</type><name>js/jquery.js</name><params>data-cfasync="false"</params></action>

哪个有效,但它会在脚本之后添加它&#39; SRC。它需要放在src之前,以便Cloudflare识别它。有没有办法做到这一点。

我尝试在第一个&#39;动作之间添加它。标签和&#39;类型&#39;标签。以及&#39; / type&#39;标签和&#39;名称&#39;标签。两者都不起作用。

1 个答案:

答案 0 :(得分:2)

需要对/app/code/core/Mage/Page/Block/Html/Head.php进行一些更改。在核心文件中进行更改是错误的,因此如果将此文件复制到/app/code/local/Mage/Page/Block/Html/Head.php并在此新文件中进行所有更改,则会更好。

首先,找到第210行(适用于Magento 1.9)。

然后替换它:

$html .= $this->_prepareStaticAndSkinElements('<script type="text/javascript" src="%s"%s></script>' . "\n",

有了这个:

$html .= $this->_prepareStaticAndSkinElements('<script type="text/javascript"%s src="%s"></script>' . "\n",

其次,转到第285行并替换它:

$html .= sprintf($format, $src, $params);

有了这个:

if (strpos($format, 'text/javascript')) {
    $html .= sprintf($format, $params, $src);
} else {
    $html .= sprintf($format, $src, $params);
}

希望有所帮助:)