function loadScript( url, callback ) {
var script = document.createElement( "script" )
script.type = "text/javascript";
script.src = url;
script.onload = function() {
callback()
};
document.head.appendChild(script);
}
// call the function...
loadScript("js/myscript.js", function() {
alert('script ready!');
});
document.writeln("<script type='text/javascript' src='Script1.js'></script>");
document.writeln("<script type='text/javascript' src='Script2.js'></script>");
var imported = document.createElement('script');
imported.src = '/path/to/imported/script';
document.head.appendChild(imported);
<script type="module">
import { hello } from './hello.mjs'; // Or it could be simply `hello.js`
hello('world');
</script>
// hello.mjs -- or it could be simply `hello.js`
export function hello(text) {
const div = document.createElement('div');
div.textContent = `Hello ${text}`;
document.body.appendChild(div);
}
import('your-file-name.js')
//this only works for javascript files
//and with bugs or half bugs it won't work
check this link:
https://stackoverflow.com/questions/950087/how-do-i-include-a-javascript-file-in-another-javascript-file
it wil tell you it in all js variants (including jQuery and node.js)
// jQuery
$.getScript('/path/to/imported/script.js', function()
{
// script is now loaded and executed.
// put your dependent JS here.
});
<script type="module">
import { hello } from './hello.mjs'; // Or the extension could be just `.js`
hello('world');
</script>