This is an alternative to the Modern Script Loading tchnique, that doesn't need to wait for the load
event.
This technique has been successfully tested down to IE9.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script>
addEventListener('message', function _(e) {
removeEventListener('message', _);
var s = document.head.appendChild(document.createElement('script'));
s.src = (s.type = e.data) == 'module' ? '/js/modern.js' : '/js/legacy.js';
});
</script>
<script type="module" src="data:text/javascript,postMessage('module','*')"></script>
<script defer src="data:text/javascript,postMessage('text/javascript','*')"></script>
</head>
</html>
Please note this technique, or any other out there, does not grant that modern module
scripts can also load dynamic import(...)
within their code.