1var imported = document.createElement('script');
2imported.src = '/path/to/imported/script';
3document.head.appendChild(imported);
1document.writeln("<script type='text/javascript' src='Script1.js'></script>");
2document.writeln("<script type='text/javascript' src='Script2.js'></script>");
1// module.js
2export function hello() {
3 return "Hello";
4}
5
6// main.js
7import {hello} from 'module'; // or './module'
8let val = hello(); // val is "Hello";
1<script type="module">
2 import { hello } from './hello.mjs'; // Or it could be simply `hello.js`
3 hello('world');
4</script>
5
6// hello.mjs -- or it could be simply `hello.js`
7export function hello(text) {
8 const div = document.createElement('div');
9 div.textContent = `Hello ${text}`;
10 document.body.appendChild(div);
11}