Skip to content

Commit 402d152

Browse files
authored
Merge pull request #15642 from webpack/set-use-credentials-without-origin-check
set crossOrigin=use-credentials without origin check
2 parents fcb0e35 + 8729f2e commit 402d152

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed

lib/css/CssLoadingRuntimeModule.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,15 @@ class CssLoadingRuntimeModule extends RuntimeModule {
108108
'link.rel = "stylesheet";',
109109
"link.href = url;",
110110
crossOriginLoading
111-
? Template.asString([
112-
"if (link.src.indexOf(window.location.origin + '/') !== 0) {",
113-
Template.indent(
114-
`link.crossOrigin = ${JSON.stringify(crossOriginLoading)};`
115-
),
116-
"}"
117-
])
111+
? crossOriginLoading === "use-credentials"
112+
? 'link.crossOrigin = "use-credentials";'
113+
: Template.asString([
114+
"if (link.src.indexOf(window.location.origin + '/') !== 0) {",
115+
Template.indent(
116+
`link.crossOrigin = ${JSON.stringify(crossOriginLoading)};`
117+
),
118+
"}"
119+
])
118120
: ""
119121
]);
120122

lib/runtime/LoadScriptRuntimeModule.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,15 @@ class LoadScriptRuntimeModule extends HelperRuntimeModule {
8787
: "url"
8888
};`,
8989
crossOriginLoading
90-
? Template.asString([
91-
"if (script.src.indexOf(window.location.origin + '/') !== 0) {",
92-
Template.indent(
93-
`script.crossOrigin = ${JSON.stringify(crossOriginLoading)};`
94-
),
95-
"}"
96-
])
90+
? crossOriginLoading === "use-credentials"
91+
? 'script.crossOrigin = "use-credentials";'
92+
: Template.asString([
93+
"if (script.src.indexOf(window.location.origin + '/') !== 0) {",
94+
Template.indent(
95+
`script.crossOrigin = ${JSON.stringify(crossOriginLoading)};`
96+
),
97+
"}"
98+
])
9799
: ""
98100
]);
99101

lib/web/JsonpChunkLoadingRuntimeModule.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,17 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
263263
'link.as = "script";',
264264
`link.href = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkScriptFilename}(chunkId);`,
265265
crossOriginLoading
266-
? Template.asString([
267-
"if (link.href.indexOf(window.location.origin + '/') !== 0) {",
268-
Template.indent(
269-
`link.crossOrigin = ${JSON.stringify(
270-
crossOriginLoading
271-
)};`
272-
),
273-
"}"
274-
])
266+
? crossOriginLoading === "use-credentials"
267+
? 'link.crossOrigin = "use-credentials";'
268+
: Template.asString([
269+
"if (link.href.indexOf(window.location.origin + '/') !== 0) {",
270+
Template.indent(
271+
`link.crossOrigin = ${JSON.stringify(
272+
crossOriginLoading
273+
)};`
274+
),
275+
"}"
276+
])
275277
: ""
276278
]),
277279
chunk

0 commit comments

Comments
 (0)