Using ES2015 Modules in Browsers

<script type="module" src="./runsfirst.js"></script>
<script type="module" src="./runssecond.js"></script>

<script type="module">
import { something } from './somewhere.js';
// ...
</script>

Browsers without ESM support don’t load scripts with a type=“module” attribute. Browsers with ESM support don’t load scripts with a nomodule attribute:

<script type="module" src="runs-when-ESM-supported.js"></script>
<script nomodule src="runs-when-ESM-is-not-supported.js"></script>

Modules must be served with the MIME type application/javascript or text/javascript . A CORS header such as Access-Control-Allow-Origin: * must also be set if a module can be imported from another domain.