What is the correct way to dynamically import JavaScript (.js) files into a parent JavaScript code, please?
I am using the following code, but it seems not correct:<
You can't use variables and functions defined in the external JS file immediatly after inserting the tag. It takes the browser a few milliseconds to load the file and execute it.
You would have to work with some kind of callback in order to have the proper loading order for your JavaScript.
For proper conditional loading of JavaScript have a look at Require.js. There the Asynchronous Module Definition pattern is implemented.