Last active
July 19, 2018 21:03
-
-
Save camille-hdl/f6ab4acba5cc4c0ce198c3acc7c9255d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- see it in action here : https://github.com/rollup/rollup-starter-code-splitting/blob/master/public/index.html --> | |
<!-- Browsers with dynamic import support --> | |
<script type="module"> | |
window.esDynamicImport = true; | |
// this will throw if dynamic import is not supported | |
import("/js/es/entrypoint.js").then(function(m) { | |
// do something | |
}); | |
</script> | |
<!-- browsers with ES6 modules but no dynamic import support --> | |
<script type="module"> | |
// if the module script tag throws, window.esDynamicImport will be undefined | |
if (!window.esDynamicImport) { | |
// get the nomodule scripts and load (or inline) them | |
const noms = Array.prototype.slice.call(document.getElementsByTagName('script'), 0).filter((x) => x.hasAttribute('nomodule')); | |
function nextLoad (nom, s) { | |
if (!(nom = noms.shift())) return; | |
s = document.createElement('script'); | |
if (nom.src) | |
s.src = nom.src, s.addEventListener('load', nextLoad), s.addEventListener('error', nextLoad); | |
else | |
s.innerHTML = nom.innerHTML; | |
document.head.appendChild(s); | |
if (!nom.src) nextLoad(); | |
} | |
nextLoad(); | |
} | |
</script> | |
<!-- No ES6 modules support : fallback to systemJS --> | |
<script nomodule src='https://unpkg.com/[email protected]/dist/system-production.js'></script> | |
<script nomodule> | |
System.import("/js/system/entrypoint.js").then(function(m) { | |
// do something | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment