The preload
directive is not performing in Chrome as expected. Below is a full HTML page that may be opened in Chrome for results comparison. It should be applying all 5 fonts; instead, it only applies the first preloaded font, makes a faux italic for what should be the second, and simply substitutes the default serif for the remaining 3.
Additionally, in the developer's console, this message appears--after about 3 seconds--for each of the five fonts:
The resource [URL] was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it wasn't preloaded for nothing.
Strangely, it did apply the first font (Muli) to the h1
and h2
tags (although making a faux italic for the h2
); you can click on the URLs in the error messages and a preview of the preloaded font will appear in the developer's console.
Any clue what's amiss here? (I've tested this on Chrome 56 on Windows 8.1 Pro.)
<!DOCTYPE html>
<html>
<head>
<title>Preload Font Test</title>
<link rel="preload" href="https://fonts.gstatic.com/s/muli/v10/zscZFkjVRGyfQ_Pw-5exXPesZW2xOQ-xsNqO47m55DA.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="https://fonts.gstatic.com/s/muli/v10/YxNEAWILjDc466nftZdqXuvvDin1pK8aKteLpeZ5c0A.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="https://fonts.gstatic.com/s/opensans/v13/k3k702ZOKiLJc3WVjuplzBampu5_7CjHW5spxoeN3Vs.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="https://fonts.gstatic.com/s/opensans/v13/PRmiXeptR36kaC0GEAetxv79_ZuUxCigM2DespTnFaw.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="https://fonts.gstatic.com/s/lato/v13/tI4j516nok_GrVf4dhunkg.woff2" as="font" type="font/woff2" crossorigin>
<style>
h1 {font-family:'Muli';font-weight:400;font-style:normal;font-size:1.5em}
h2 {font-family:'Muli';font-weight:400;font-style:italic;font-size:1.5em}
h3 {font-family:'Open Sans';font-weight:700;font-style:normal;font-size:1.5em}
h4 {font-family:'Open Sans';font-weight:700;font-style:italic;font-size:1.5em}
h5 {font-family:'Lato';font-weight:900;font-style:normal;font-size:1.5em}
</style>
</head>
<body>
<h1>This should be in Muli regular 400 -- and it is!</h1>
<h2>This should be in Muli Italic 400 -- but it's faux Muli Italic :(</h2>
<h3>This should be in Open Sans Bold 700 -- but it's the default serif!</h3>
<h4>This should be in Open Sans BoldItalic 700 -- but it's the default serif!</h4>
<h5>This should be in Lato ExtraBold 900 -- but it's the default serif!</h5>
</body>
</html>
I've found the solution to this. Sadly, the W3C spec on
preload
links doesn't make this clear, and there seems to be a lot of confusion about this where programmers have posted questions about it, especially as regards the developer's console error message (Google that by itself to see how many people are getting it and are perplexed by it; it's indicative of how misunderstood this very useful directive is).You cannot use the
preload
link by itself to load fonts. It must be used in conjunction with@font-face
. Specifically, thepreload
link must precede the@font-face
directive, and@font-face
must occur soon after thepreload
link, if not immediately. It would seem that in the<head>
section, thepreload
link should come last in your links, and then@font-face
should immediately follow, either in a linked style sheet or in a<style>
section that follows.Here is a corrected version of the original code:
This works, and it does, in fact, collect your fonts as part of the initial navigation of the critical rendering path, which is the principal benefit.
preload
is currently only supported by Chrome and Opera, but other browsers will surely follow.