How to dynamically load a JS file in JavaScript https://www.educative.io/answers/how-to-dynamically-load-a-js-file-in-javascript function loadJS ( FILE_URL , async = true ) { let scriptEle = document . createElement ( "script" ); scriptEle . setAttribute ( "src" , FILE_URL ); scriptEle . setAttribute ( "type" , "text/javascript" ); scriptEle . setAttribute ( "async" , async ); document . body . appendChild ( scriptEle ); // success event scriptEle . addEventListener ( "load" , () => { console . log ( "File loaded" ) }); // error event scriptEle . addEventListener ( "error" , ( ev ) => { console . log ( "Error on loading file" , ev ); ...
Comments
Post a Comment