Skip to content

Instantly share code, notes, and snippets.

@developit
Last active May 27, 2020 12:56
Show Gist options
  • Save developit/463a1ea6f6a92f35ede6eff9599e0684 to your computer and use it in GitHub Desktop.
Save developit/463a1ea6f6a92f35ede6eff9599e0684 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Demo: Treat Safari 11 and Prior as nomodule</title>
</head>
<body>
<script>
if (/Safari\/5/.test(navigator.userAgent)) {
var $fss = function () {
for (var i of document.scripts) {
if (i.noModule) {
i.noModule = false
var un = document.createElement('script')
for (var x of i.attributes) un.setAttribute(x.name, x.value)
i.parentNode.replaceChild(un, i)
}
}
}
addEventListener('DOMContentLoaded', $fss)
addEventListener('beforeload', function(e) {
if (e.target.type=='module') e.preventDefault()
$fss()
}, true)
}
</script>
<script type="module" src="hello.mjs"></script>
<script nomodule src="hello.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment