Search code examples
javascripthtmlscript-tag

when the script abrupts another script


WHATWG spec has interesting step in prepare the script element algorithm:

Otherwise, immediately execute the script element el, even if other scripts are already executing.

What is that case? How does one script may pause of executing another script?


Solution

  • Given the constraints, it's a script that is not a module, does not have a src attribute, and is inserted during a script execution. I think the following example qualifies:

    <script>
    console.log("before");
    document.write(`<script>
    console.log("nested");
    <\/script>`);
    console.log("after");
    </script>