Skip to content

Instantly share code, notes, and snippets.

View lgwebdream's full-sized avatar
🏠
Working from home

志佳 lgwebdream

🏠
Working from home
View GitHub Profile
@lgwebdream
lgwebdream / safari-nomodule.js
Created June 27, 2019 13:51 — forked from samthor/safari-nomodule.js
Safari 10.1 `nomodule` support
/**
* Safari 10.1 supports modules, but does not support the `nomodule` attribute - it will
* load <script nomodule> anyway. This snippet solve this problem, but only for script
* tags that load external code, e.g.: <script nomodule src="nomodule.js"></script>
*
* Again: this will **not** prevent inline script, e.g.:
* <script nomodule>alert('no modules');</script>.
*
* This workaround is possible because Safari supports the non-standard 'beforeload' event.
* This allows us to trap the module and nomodule load.