4

I'm trying to add CloudFlare's RocketLoader JS attribute tag data-cfasync='true' to some of my files manually.

I've learned how to load js files through layout.xml, but I'm not sure how to add the attribute through the XML.

What I have now:

<script type="text/javascript" src="http://website.com/js/prototype/prototype.js">

What I'm trying to get to:

<script data-cfasync="true" type="text/javascript" src="http://website.com/js/prototype/prototype.js">
Fabian Blechschmidt
  • 35,388
  • 8
  • 75
  • 182
James
  • 43
  • 2

1 Answers1

1

If you want to add this attribute data-cfasync='true' to the JS DOM nodes, there is no way.

The JS is created here:

\Mage_Page_Block_Html_Head::getCssJsHtml

and the sprintf is resolved here:

\Mage_Page_Block_Html_Head::_prepareStaticAndSkinElements

and I don't see any way to inject attributes, so I would suggest you rewrite the Mage_Page_Block_Html_Head and change this method(s) as you need them.

Fabian Blechschmidt
  • 35,388
  • 8
  • 75
  • 182
  • It can't be added here? 'action method="addItem">skin_jsmobilemenu/jquery-1.7.2.min.js'

    Thanks for your reply

    – James Mar 13 '14 at 05:43
  • correct, this is the method where the JS/Css generation starts in the very beginning. You add it all via addItem/addJs/addSkinJs/addCss, then it is added to an array, requested in the template and delivered by getCssJsHtml and finally created by _prepareStaticAndSkinElements – Fabian Blechschmidt Mar 13 '14 at 05:53