The crossorigin Attribute Requirement
What you'll learn: Why font preloads require the crossorigin attribute even when loading fonts from your own domain.
When you preload fonts using <link rel="preload">, you must add the crossorigin attribute to the tag—even if the font file lives on the same domain as your HTML page. This seems counterintuitive at first, but it's essential for how browsers handle font requests.
Why Fonts Are Special
Browsers fetch fonts using CORS (Cross-Origin Resource Sharing) mode by default, regardless of where they're hosted. This is a security measure built into the CSS Font Loading specification. When your CSS requests a font via @font-face, the browser makes that request in "anonymous" CORS mode.
Here's the problem: if your preload request doesn't use the same CORS mode, the browser treats it as a completely different resource. You end up downloading the font twice—once for the preload (without CORS), and once when the CSS actually needs it (with CORS). The preload becomes useless.
The Correct Syntax
<link rel="preload"
href="/fonts/myfont.woff2"
as="font"
type="font/woff2"
crossorigin>
The crossorigin attribute (or crossorigin="anonymous") ensures your preload request matches the CORS mode that the CSS @font-face rule will use later.
The Same-Origin Confusion
Even though "crossorigin" sounds like it only applies to external resources, it actually controls the request mode, not just the domain. Same-origin fonts still need CORS mode matching.
Key Takeaway: Always include crossorigin when preloading fonts—it ensures the preload matches how CSS will request the font, preventing duplicate downloads even for same-origin files.