I am building a jquery plugin im using this code to include external files:
if(!$("script[src*='https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.js']").length){
var myScript = "<script src='https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.js'></script>";
$(myScript).appendTo("head");
}
It works great with promise js , but when i try this with crypto-js and cryptico scripts it does append the files to the html but for some reason i can't access the imported scripts. this is the error i get :
Uncaught TypeError: Cannot read property 'lib' of undefined
Try this way:
if($("script[src*='https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.js']").length < 1){
$.getScript('https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.js');
}