How to make JavaScript run Asynchronously?

Deferred Loading JavaScript for Old Browsers

For older browser that doesn't support
defer
or
async
attributes, you can
use JavaScript to insert a JavaScript by using
document.createElement(), the newly inserted JavaScript
will run after the DOM is ready.

Suppose you want to use JavaScript to insert the following JavaScript code.

<script>alert("yay!");</script>

Solution: use JavaScript to create the script element and its contents, then insert this node into DOM.