title: How to wait for document.write to complete
body: <p>I am trying to write some script fall-back code so that if jQuery and jQuery Validator is not available from a CDN I load a local version. Note that the following script is in a separate file to support Content Security Policy (CSP).</p>
  
  <pre><code>(window.jQuery || document.write('&lt;script src="/js/jquery.js"&gt;&lt;\/script&gt;'));
  ($.validator || document.write('&lt;script src="/js/jquery-validate.js"&gt;&lt;\/script&gt;'));
  </code></pre>
  
  <p>If jQuery is not available a new script tag is written to the end of the document but then the next line errors saying that $ is undefined. How can I wait for the document write to finish loading up the document before executing the next line?</p>