Dynamic import() js file with aync/await
If you want this example to work in IE10, just add it to index.html
<script type="text/javascript">
if (!('Promise' in window)) {
var script = document.createElement("script");
script.src = "https://polyfill.io/v3/polyfill.min.js?features=Promise";
document.getElementsByTagName('head')[0].appendChild(script);
}
</script>
If you want to load a js file, all you have to do is add data-module="js-module-name"
. An example below:
<button id="background" class="button-primary" data-module="background">change the background</button>
In this case, the background.js
file will be dynamically loaded after clicking the button.