Skip to content

Commit 03c371e

Browse files
authored
chore: add comment about crossorigin attribute for script module (#15040)
1 parent b93dfe3 commit 03c371e

File tree

1 file changed

+6
-0
lines changed
  • packages/vite/src/node/plugins

1 file changed

+6
-0
lines changed

packages/vite/src/node/plugins/html.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,12 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
675675
attrs: {
676676
...(isAsync ? { async: true } : {}),
677677
type: 'module',
678+
// crossorigin must be set not only for serving assets in a different origin
679+
// but also to make it possible to preload the script using `<link rel="preload">`.
680+
// `<script type="module">` used to fetch the script with credential mode `omit`,
681+
// however `crossorigin` attribute cannot specify that value.
682+
// https://developer.chrome.com/blog/modulepreload/#ok-so-why-doesnt-link-relpreload-work-for-modules:~:text=For%20%3Cscript%3E,of%20other%20modules.
683+
// Now `<script type="module">` uses `same origin`: https://github.com/whatwg/html/pull/3656#:~:text=Module%20scripts%20are%20always%20fetched%20with%20credentials%20mode%20%22same%2Dorigin%22%20by%20default%20and%20can%20no%20longer%0Ause%20%22omit%22
678684
crossorigin: true,
679685
src: toOutputPath(chunk.fileName),
680686
},

0 commit comments

Comments
 (0)