Instantly share code, notes, and snippets.

Embed
What would you like to do?
Will it double-fetch? Browser behavior with `module` / `nomodule` scripts

Testing double-fetching of module/nomodule JS code (including the Safari hack)

<script type="module" src="module.js"></script>
<script nomodule src="nomodule.js"></script>

Test page: https://jg-testpage.github.io/es-modules/module-nomodule/

IE/Edge Firefox Chrome Safari fetches module fetches nomodule executes
15- 59- 55- v v nomodule
16 v v module
17-18 double! v module
56-60 10.0- v nomodule
60+ 61+ 10.1+ v module

Summary:

  • no browser does double execution
  • Safari never fetches more than necessary (provided the Safari hack for 10.1 / iOS 10.3 is included in the top of HTML)
  • modern browsers, except Edge, never fetch more than necessary
  • pre-2018 browsers (except Safari) do double fetches
  • newest Edge does triple fetch (2x module + 1x nomodule)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment