title: How to prevent a race condition when loading on-demand JavaScript files?
body: <p>To speed up things, my web application loads JavaScript files for certain features on-demand using jQuery's ajax call. I've encountered a race condition problem, though. For example, file B.js depends on file A.js. I've configured a list like list=[A.js,B.js] and I iterate over this list and asynchronously get the scripts. How can I prevent this race condition?</p>
  
  <p>The code that loads the JavaScript files is something like:</p>
  
  <pre><code>loadJS: function(url) {
      $.ajax({url: url, dataType: 'script', success: function(){}});
  }
  </code></pre>