<scripttype="module"> import { hello } from'./hello.mjs'; // Or the extension could be just `.js` hello('world'); </script>
// hello.mjs -- or the extension could be just `.js` export function hello(text) { const div = document.createElement('div'); div.textContent = `Hello ${text}`; document.body.appendChild(div); }
functiondynamicallyLoadScript(url) { var script = document.createElement("script"); // create a script DOM node script.src = url; // set its src to the provided URL
document.head.appendChild(script); // add it to the end of the head section of the page (could change 'head' to 'body' to add it to the end of the body section instead) }