title: How to pause javascript until something is done?
body: <p>To be as fast as possible, I will jump into the topic right now.
  I want to delay the script before jQuery is loaded.</p>
  
  <p>Here is my problem: I have code which inserts <code>jQuery.js</code> automatically when jQuery isn't loaded yet:</p>
  
  <pre><code>if(typeof jQuery=="undefined") {
      var s=document.createElement("script");
      s.type="text/javascript";
      s.async=true;
      s.src="http://code.jquery.com/jquery-1.5.1.min.js";
      var x=document.getElementsByTagName("script")[0];
      x.parentNode.insertBefore(s, x);
  }
  
  $(document).ready(function() {
      //My code goes here, right?
  });
  </code></pre>
  
  <p>It works perfectly to insert the script, but the problem is <code>$(document).ready()</code> does not wait until the script is loaded completely, it jumps down immediately while the script is being loaded. I want to pause right there, what should I do?</p>