Skip to content

Instantly share code, notes, and snippets.

@cooljl31
Last active October 30, 2019 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cooljl31/b291b1b44a72dbd7ca3bab3e6f6b3032 to your computer and use it in GitHub Desktop.
Save cooljl31/b291b1b44a72dbd7ca3bab3e6f6b3032 to your computer and use it in GitHub Desktop.
<!-- use a module script to detect modern browsers: -->
<script type=module>
self.modern = true
</script>
<!-- now use that flag to load modern VS legacy code: -->
<script defer>
addEventListener('load', function () {
var s = document.createElement('script')
if (self.modern) {
s.src = './module.js'
s.type = 'module'
s.defer = true
s.async = true
}
else {
s.src = './module.js'
s.defer = 'defer'
s.async = 'async'
}
document.head.appendChild(s)
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment