I want to add an external javascript file in another javascript file. For example my file name is info.js, now I want to include "https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js" in my info.js file.
I don't want to use this CND <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
in my html file like this.
I did the following code, which adds the CDN to the html file, but it's not working.
function include(file) {
var script = document.createElement('script');
script.src = file;
document.getElementsByTagName('script').item(0).before(script);
}
/* Include Many js files */
include('https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js');
Actually I am not good at English. I hope you understand my problem. Have any solution for me?
Thanks