Home  >  Q&A  >  body text

javascript - Why is it loaded asynchronously when dynamically creating <script> tags to load external link JS files?

b.js file code:
var script = document.createElement("script");
script.src = "a.js";
document.body.appendChild(script);

Why does this load the a.js file asynchronously? If the code in the b.js file has not been executed yet, but the a.js file has been loaded, should we execute the code in a.js or continue to execute b. What about the rest of the code in js?
I don’t quite understand, please give me some advice

我想大声告诉你我想大声告诉你2662 days ago886

reply all(1)I'll reply

  • 三叔

    三叔2017-07-05 10:51:55

    Execute a.js first and then continue to execute the remaining code of b.js. This is a sequential loading execution form.

    reply
    0
  • Cancelreply