1

I have tried to load js asynchronously in Magento 2 following a recommendation from the Google PageSpeed Insights tool. Unfortunately my updates in the relevant layout file break the page.

CURRENT LAYOUT XML

<head>
 <script async src="js::myown.js"/>
 <script async src="js::another.js"/>
 <script async src="js::afinal.js"/>
</head>

Can someone please recommend a solution to the above to get the async loading working?

1
  • I recommend looking at using require.js to add your scripts, here is a good article explaining it.
    – Ben Crook
    May 2, 2017 at 8:24

1 Answer 1

4

Try attribute async="async" between script tag

<script async="async" src="Vendor_ModuleName::js/your.own.js"/>

or in theme

<script async="async" src="js/your.own.js"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.