next/script support script type="module" #75516
jboyesreach
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Goals
Support loading script tags via next/script, which require the type="module" attrib
Non-Goals
break existing next/script features
Background
The problem with next/script for these scripts is in the auto-preload functionality. Nextjs adds a <link rel="preload... tag, this preloads the script, then when the <script> tag in body also requests the script, the request is not a cache-hit resulting in the whole script being downloaded twice. It's a cache miss because script with type=module secretly has crossorigin="omit" https://web.dev/articles/modulepreload#why_doesnt_link_relpreload_work_for_modules
Current alternatives:
Proposal
next/script knows about the type="module" attrib. He can use that to switch from ReactDOM.preload() to ReactDOM.preloadModule()
Beta Was this translation helpful? Give feedback.
All reactions