title: Loading library with document.write from another JS file
body: <p>I have an older validation form which is depends on the prototype.js library.</p>
  <p>Unfortunately I can't include a reference to the prototype.js library on the page. I do not control that form's code.</p>
  <p>How would I approach the issue of loading this outside of editing the pages that need it? That is, I need to load the library from another JavaScript library I <strong>do</strong> control. Let me explain.</p>
  <p>Each page with the form has this include script:</p>
  <pre><code>&lt;script src=&quot;http://domain/validationScript.js&quot;
      type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
  </code></pre>
  <p><strong>And inside the script I was thinking of doing something like this...</strong></p>
  <pre><code>document.write(unescape(
      &quot;%3Cscript src='//ajax.googleapis.com/ajax/libs/prototype/1.6.1/prototype.js' type='text/javascript'%3E%3C/script%3E&quot;
    ));
  </code></pre>
  <p>but it doesn't load <code>prototype.js</code> before the script.</p>
  <p>What am I doing wrong?</p>
  <hr />
  <p>Ok, it's clear with the DOM sequence that it has a race condition where I can't use the loaded script in the script that's writing the include to the page.</p>
  <p>But then how can I load the library from a script that itself needs to execute the code from the library it's loading?</p>