It is really simple:
if(somethingIsTrue) { var sc = document.createElement('script'); sc.src = 'http://code.jquery.com/jquery-1.5.js'; sc.type = 'text/javascript'; if(typeof sc['async'] !== 'undefined') { sc.async = true; } document.getElementsByTagName('head')[0].appendChild(sc); }
Jacob Relkin
source share