title: <script> onload fires when ...?
body: <p>In the function below from Mozilla, JS is used to add a  tag into the document. I'm confused when the onload event fires. Does onload fire when the script starts to download or has already downloaded?</p>
  
  <pre><code>function prefixScript(url, onloadFunction) {
    var newScript = document.createElement("script");
    newScript.onerror = loadError;
    if (onloadFunction) { newScript.onload = onloadFunction; }
    document.currentScript.parentNode.insertBefore(newScript, document.currentScript);
    newScript.src = url;
  }
  </code></pre>
  
  <p><a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement" rel="nofollow noreferrer">https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement</a></p>
  
  <p>Thank you</p>