Categories
JavaScript Answers

How to load scripts asynchronously with JavaScript?

Spread the love

To load scripts asynchronously with JavaScript, we use the async or defer attributes.

For instance, we write

<script async src="script.js" onload="myInit()"></script>

or

<script defer src="script.js" onload="myInit()"></script>

to load script.js asynchronously.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *