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!');
});
export function greet(name) {
return `Hello, ${name}`;
}
export const message = "How you doing?";
///
import { greet, message } from "./utils.js";
const greet_scaler = greet("Scaler");
console.log(greet_scaler); // Hello, Scaler
console.log(message); // How you doing?
document.writeln("<script type='text/javascript' src='Script1.js'></script>");
document.writeln("<script type='text/javascript' src='Script2.js'></script>");
// 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>