Skip to content

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>

Update September 2020: life's almost good. Edge Chromium is widely rolled out, and Safari 14.0 ships soon with a fix.

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

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

Summary:

  • no browser does double execution (provided the Safari hack)
  • modern Chrome, Edge, Firefox never fetch more than necessary
  • Safari <11 may or may not double fetch (even with the hack); it does not on small test pages, but in real complex pages it does (it seems deterministic, but not clear what's the exact trigger)
  • Safari 11+ may still double fetch in some cases (see https://bugs.webkit.org/show_bug.cgi?id=194337)
    • This will apparently be fixed in Safari 14.0 (October 2020)
  • pre-2018 browsers do double fetches
  • Edge 17-18 does triple fetch (2x module + 1x nomodule). This about 80% of all Edge as of April 2020, but being phased out by Edge 80+.
@AndrewGibson27

This comment has been minimized.

Copy link

@AndrewGibson27 AndrewGibson27 commented Jan 23, 2020

Webkit has patched the Safari 11+ double-fetch bug: https://bugs.webkit.org/show_bug.cgi?id=194337

@jakub-g

This comment has been minimized.

Copy link
Owner Author

@jakub-g jakub-g commented Jan 31, 2020

👍 thx for the comment @AndrewGibson27. Hopefully this makes it into Safari 13.1 (for now it's in Technical Preview only)

@indexzero

This comment has been minimized.

Copy link

@indexzero indexzero commented Feb 7, 2020

Was your PR to caniuse (awesome btw – super helpful for me) supposed to show green for Safari 11-13 @jakub-g? Based on the Webkit comment above it seems like caniuse for es6 modules should be showing Yellow:

Screen Shot 2020-02-07 at 6 01 00 AM

My gut is saying regression in caniuse, but I wanted surface it your way since it was your contribution originally.

@jakub-g

This comment has been minimized.

Copy link
Owner Author

@jakub-g jakub-g commented Feb 20, 2020

@indexzero I think I made PR to caniuse before I found out Safari 11+ double fetching, not sure. My PR touches only Edge.

Agree there's inconsistency - Edge 16-18 and Safari 10.1 should be marked with same color on caniuse (whether or yellow or green, I can't tell; not sure what is the meaning; probably yellow up to Edge 18 and Safari 13/ ios 13.2 inclusive, due to double fetching?)

@AndrewGibson27

This comment has been minimized.

Copy link

@AndrewGibson27 AndrewGibson27 commented Apr 8, 2020

It appears this didn't make it into Safari 13.1 😢

@siakaramalegos

This comment has been minimized.

Copy link

@siakaramalegos siakaramalegos commented Apr 13, 2020

@jakub-g, I think normal loading works on the new Chromium-based Edge now. I ran your page, and I think it only downloads module.js, but I wasn't sure if you were testing other edge cases too.

@davidpelayo

This comment has been minimized.

Copy link

@davidpelayo davidpelayo commented Apr 17, 2020

Could you please, @AndrewGibson27, provide a link with where you saw that? Thanks!

@danoc

This comment has been minimized.

Copy link

@danoc danoc commented Apr 22, 2020

It isn't working for me in Safari 13.1 either:

image

It does work in Safari Technology Preview 104 which corresponds a the future Safari 13.2 release.

image

@jakub-g

This comment has been minimized.

Copy link
Owner Author

@jakub-g jakub-g commented Apr 27, 2020

Safari 13.1 is based on Webkit TP98 [0]

https://bugs.webkit.org/show_bug.cgi?id=194337 was closed on 23 Jan 2020 which means it was not in TP99 (released 22 Jan 2020), it was probably shipped in TP100 (05 Feb 2020).

The bug fix is hence expected in Safari 14.0 in October 2020.

[0] https://gist.github.com/jakub-g/48a16195280a7023f570ffa5c8a4eae5
[1] https://webkit.org/blog/9992/release-notes-for-safari-technology-preview-99/
[2] https://webkit.org/blog/10024/release-notes-for-safari-technology-preview-100/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.