A font preload always needs crossorigin

I added a font preload to the HTML to reduce text reflow on the pages with web fonts:

<link rel="preload" href="/fonts/book.ttf" as="font">

The pages and the fonts are on the same domain, but the preload still didn’t work and the browser downloaded the font twice.

The reason is how browsers fetch fonts. Fonts referenced by @font-face in CSS are always loaded in CORS mode, even if they come from the same origin. A preload without crossorigin uses no-CORS mode. Because the request modes are different, the browser can’t reuse the preload.

The fix is simple. I had to add the crossorigin attribute to the preload tag:

<link rel="preload" href="/fonts/book.ttf" as="font" crossorigin>

Google Chrome is very clear about this issue in the console:

A preload for 'https://example.com/fonts/book.ttf' is found, but is not used because the request credentials mode does not match. Consider taking a look at crossorigin attribute.
The resource https://example.com/fonts/book.ttf was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.
← All notes