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).
(window.jQuery || document.write('<script src="/js/jquery.js"><\/script>'));
($.validator || document.write('<script src="/js/jquery-validate.js"><\/script>'));
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?