async/defer attributes and DOM construction

4. DOM injection (async true)

Result

Hello World!

Markup

<script>
function load(src, async) {
    var js = document.createElement('script');
    js.type = 'text/javascript';
    js.async = async;
    js.src = src;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(js, s);
}
</script>
<p id="result">
    Hello
    <script>load("A.js", true);</script>
    <script>load("B.js", true);</script>
    <script>load("C.js", true);</script>
    World!
</p>

DOM elements and Events