HTML <script> Asynchronous attribute in Magento

I would like to try to insert the async attribute in the Prototype JavaScript script tag in Magento 1.9.1:

 <script type="text/javascript" src="http://www.mywebsite.com/media/js/ec1651c8b1a4ea49a916679f1e120ccf.js"></script> 

I would get this result:

 <script type="text/javascript" src="http://www.mywebsite.com/media/js/ec1651c8b1a4ea49a916679f1e120ccf.js" async></script> 

Where do I need to insert "async"? What is a file with this code? Thanks

+7
javascript asynchronous prototype
source share
2 answers

Look at the file app/design/frontend/<yourlayout>/<yourtheme>/layout/page.xml (or copy app/design/frontend/base/default/layout/page.xml to your theme).

Inside this file, find the following lines:

 <!-- ... --> <block type="page/html_head" name="head" as="head"> <action method="addJs"><script>prototype/prototype.js</script></action> <!-- ... --> </block> <!-- ... --> 

And change addJs to:

 <!-- ... --> <block type="page/html_head" name="head" as="head"> <action method="addJs"><script>prototype/prototype.js</script><params>async</params></action> <!-- ... --> </block> <!-- ... --> 

Since you use the javascript magento merge function, you need to apply this change to each addJs definition, since Magento will group files using params .

+15
source share

You make a small mistake. This is actually the correct answer to the question above.

 <!-- ... --> <block type="page/html_head" name="head" as="head"> <action method="addJs"><script>prototype/prototype.js</script><params>async="async"</params></action> <!-- ... --> </block> <!-- ... --> 
0
source share

All Articles