Skip to content

Commit cceab9e

Browse files
authored
Remove crossorigin from preload hints for same-origin vendor assets (#304)
* Remove crossorigin from preload hints for same-origin vendor assets Vendor assets are served from /vendor/... (same origin), so crossorigin attribute on preload hints causes a credentials mode mismatch. The browser preloads with anonymous credentials but requests without, resulting in cache misses and double fetching. * remove jsdelivr hint, we dont use it at all currently
1 parent fd38ed8 commit cceab9e

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

_headers

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ csp:
6464
hints:
6565
all: [
6666
'</sw.js>; rel=serviceworker',
67-
'<https://cdn.jsdelivr.net/>; rel=preconnect; pr=1.0; crossorigin',
6867
'<//cdn.carbonads.com/>; rel=dns-prefetch; pr=0.25',
6968
'<//srv.carbonads.net/>; rel=dns-prefetch; pr=0.25'
7069
]
@@ -92,7 +91,7 @@ Add resource hints for site-wide css.
9291
Add resource hints for site-wide vendor css.
9392
{% endcomment %}
9493
{% for res in site.vendor.css %}
95-
{% capture hint %}<{{ res.href }}>; rel=preload; as=style; pr=1.0; crossorigin{% endcapture %}
94+
{% capture hint %}<{{ res.href }}>; rel=preload; as=style; pr=1.0{% endcapture %}
9695
{% assign all = all | push:hint %}
9796
{% endfor %}
9897

@@ -103,7 +102,7 @@ Add resource hints for site-wide font faces.
103102
{% for style in family[1] %}
104103
{% for href in style[1] %}
105104
{% if href contains '.woff2' %}
106-
{% capture hint %}<{{ href }}>; rel=preload; as=font; pr=1.0; crossorigin{% endcapture %}
105+
{% capture hint %}<{{ href }}>; rel=preload; as=font; pr=1.0{% endcapture %}
107106
{% assign all = all | push:hint %}
108107
{% endif %}
109108
{% endfor %}
@@ -146,7 +145,7 @@ Add resource hints for docs js.
146145
Add resource hints for docs vendor js.
147146
{% endcomment %}
148147
{% for res in site.vendor.js %}
149-
{% capture hint %}<{{ res.href }}>; rel=preload; as=script; pr=1.0; crossorigin{% endcapture %}
148+
{% capture hint %}<{{ res.href }}>; rel=preload; as=script; pr=1.0{% endcapture %}
150149
{% assign docs = docs | push:hint %}
151150
{% endfor %}
152151

@@ -178,7 +177,7 @@ Add link header for doc pages.
178177

179178
{% for res in site.builds %}
180179
/docs/{{ res[0] }}*
181-
Link: <{{ res[1].href }}>; rel=preload; as=script; pr=1.0; crossorigin
180+
Link: <{{ res[1].href }}>; rel=preload; as=script; pr=1.0
182181
{% endfor %}
183182

184183
{% comment %}

assets/js/boot.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
function addStyleSheet(res) {
1010
var link = document.createElement('link')
1111

12+
// Note: crossOrigin is only needed for cross-origin requests with SRI.
13+
// Since vendor assets are now served from same origin (/vendor/...),
14+
// this condition won't match and crossOrigin won't be set - which is correct.
15+
// If loading from external CDNs again, this enables CORS for SRI verification.
1216
if (res.integrity &&
1317
res.href.slice(0, 6) === 'https:') {
1418
link.crossOrigin = 'anonymous'

0 commit comments

Comments
 (0)