title: Is order of script onload and window.onload well defined when the script is a DOM node created dynamically from a loaded script?
body: <p>File <code>loader.js</code>:</p>
  
  <pre><code>function main()
  {
    if (typeof window !== 'undefined') {
      var script = window.document.createElement('script')
      script.src = 'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.core.min.js'
      script.onload = function () { console.log('script loaded') }
      window.onload = function () { console.log('window loaded') }
      window.document.head.appendChild(script)
    } else {
      console.log('window not available yet')
    }
  }
  
  if (typeof module !== 'undefined' &amp;&amp; module.exports) {
    exports.main = main
  }
  
  main()
  </code></pre>
  
  <p>File <code>window.html</code>:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;Test&lt;/title&gt;
      &lt;script src="loader.js"&gt;&lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;div&gt;Test&lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Console output when I open this HTML page:</p>
  
  <pre><code>script loaded
  window loaded
  </code></pre>
  
  <p>My question:</p>
  
  <p>In the above code, is it guaranteed that the script onload event always fires before the window onload?</p>