title: I'm loading scripts with setTimeout, can you find a faster way?
body: <p>I have one file called <strong>main.min.js</strong>. This file has some parts which require the library <strong>pixi.min.js</strong>. The fastest way I can come up with to load these two parts is:</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;script async src="//cdnjs.cloudflare.com/ajax/libs/pixi.js/3.0.11/pixi.min.js"&gt;&lt;/script&gt;
  &lt;script async src="static/js/main.min.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p><strong>JAVASCRIPT</strong></p>
  
  <pre><code>function waitForJS() {
          var shouldStop;
  
          if (typeof window.PIXI !== "undefined") {
              shouldStop = true;
          }
  
          if (shouldStop === true) {
              //PIXI has loaded
              ThePixiFunction();
              return;
          }
  
          setTimeout(waitForJS,30);
  } waitForJS();
  </code></pre>
  
  <hr>
  
  <p>The reason I think this is the fastest way (for me) is because both files start loading at the same time, yet main.min.js starts executing before PIXI loads, and only the functions that need PIXI waits for it. Is there something about this I've overlooked? Or is there any better way of loading these two files?</p>