js appendchild wait for callback
function injectScript(src,callback){
var script = document.createElement('script');
script.src = src;
script.onload=function(){
callback();
}
document.head.appendChild(script);
}
injectScript('https://www.mysite.com/somescript.js', function(){
//the script is now all loaded
});