title: function fails to load a script
body: <p>I am using the following function to load scripts into a HTML file,</p>
  
  <pre><code>function addScript(src){
   var script = document.createElement('script');
   var location = "javascripts/";
   src =location + src;
   script.setAttribute('src', src);
   document.body.appendChild(script);
  };
  
  addScript('george.js');
  addScript('fred.js');
  addScript('main.js')
  </code></pre>
  
  <p>However, it seems to be able to load files which are too big (as in 200 lines). For example, if george.js has a class George, and the file is too long, attempts to create a new George() would fail. </p>
  
  <p>I am convinced that it is a loading size problem because of the following:</p>
  
  <p>1) new George would still fail if I comment out almost everything out from george.js.</p>
  
  <p>2) new George would succeed if I delete any 10 functions from george.js.</p>
  
  <p>3) new George would succeed if I split it up into 2 files</p>
  
  <p>4). new Fred would fail if I add a lot of comments in fred.js.</p>
  
  <p>5)To be clear, george.js can be </p>
  
  <pre><code>function George(){};
  </code></pre>
  
  <p>and I could call:</p>
  
  <pre><code>var george = new George();
  </code></pre>
  
  <p>in my file. However, if george.js becomes</p>
  
  <pre><code>function George(){};
  
  /* 
  (Insert hundreds of lines of comments here)
  */
  </code></pre>
  
  <p>the code </p>
  
  <pre><code>var george = new George();
  </code></pre>
  
  <p>will cause </p>
  
  <pre><code>ReferenceError: George is not defined
  </code></pre>
  
  <p>Why does this function have trouble loading a file of roughly 200 lines? And what can I do to deal with the problem?</p>
  
  <p>Edit:</p>
  
  <p>Attempt to try the window.setTimeout function.</p>
  
  <pre><code>AfterTimeout = function(){
    var george = new George();
  }
  
  
  window.setTimeout(AfterTimeout , 3000);
  </code></pre>
  
  <p>This does indeed seem to work.</p>
  
  <p>I have ultimately made it work by setting script.async = false;.</p>