To correctly preload font files, we're told we always need the crossorigin
attribute applied to our <link rel="preload" />
tags, e.g:
<link rel="preload" href="fonts/comicsans.woff2" as="font" type="font/woff2" crossorigin>
Can anybody give me the true reason for this? All I can find are links in MDN that just dictate this requirement, without going into any detail as to why:
https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types/preload#cors-enabled_fetches
When preloading resources that are fetched with CORS enabled (e.g. fetch(), XMLHttpRequest or fonts), special care needs to be taken to setting the crossorigin attribute on your element. The attribute needs to be set to match the resource's CORS and credentials mode, even when the fetch is not cross-origin.
As mentioned above, one interesting case where this applies is font files. Because of various reasons, these have to be fetched using anonymous-mode CORS (see Font fetching requirements).
It seems counterintuitive to my understanding of CORS, and why it's necessary. I'm sure there's a good reason for this, I just can't find it.
Before anybody just links to the same docs I'm talking about, see below:
https://drafts.csswg.org/css-fonts/#font-fetching-requirements
I'd really like an in depth answer from somebody who really knows why this is a requirement, and what it's purpose is, with some evidence (docs, etc) to back it up.