-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
suggest font-display optional if font is preloaded, to reduce layout shift #11227
Comments
A few extra thoughts:
I'm on the verge of saying a new audit isn't necessary, but I think there's room to say existing
+1. I don't think we should duplicate the complicated preload logic here. We already have an audit that tells them to preload their font I like the idea of this being an extra upgrade on top you unlock :) |
Not observable in Lighthouse because, as you know, CLS can't be simulated and is just what we observe. There's still a swap period for There's some work being done to detect an icon font. Maybe we can just ignore icon fonts.
Not in Chrome >=83, but I see your point for other browsers w/o this same optimization. |
Not just simulation. The block period is like 3s for a single request so all but the slowest connections will avoid a layout shift. Lighthouse Slow 4G applied throttling would be hard pressed to fall into the swap period.
Hang on now that I've actually read the post on it... :) I think Given this reality, the advice IMO should be more like "oh you've set a font to be optional, then you should definitely preload it, regardless of where it is in the discovery tree because Chrome does this special thing" and it's a separate audit that would hypothetically report savings on CLS if we could compute it :) Not you should set every font you preload to be |
"Starting in Chrome 83, preloaded fonts with font-display: optional will result in no FOIT or layout shifts." I don't think this should be tied to preload. "I think optional is a mistake in every mobile circumstance you need a custom font." We can potentially have this audit identify icon fonts, and not propose migrating to font-display:optional in those cases. |
The linked article says specifically
I interpret those statements to mean this optimization that the first render cycle is skipped only applies if the font is preloaded. Later on though it says...
@housseindjirdeh would you mind helping us out here by clarifying your intent? :) My practical experiments suggest the optional font will only be used if |
Alternatively @tdresser if you were just phrasing your insider Chrome knowledge as a question to be nicer and not actually wondering what happens like we are, then please continue to share your teachings are welcome! 😆 |
Hi, I'm the one who implemented the change, so feel free to ping me if you want to know about the technical details. I think it's good idea to suggest preloading for
And I'm not sure we should suggest setting Alternative thoughts:
|
Awesome, thanks for chiming in @xiaochengh! It sounds like we should proceed as planned with your existing implementation in #11255 @lemcardenas 👍 (and perhaps add a note about allowing For clarity @xiaochengh, does preloading an Re-reading @housseindjirdeh's article and from your and @tdresser 's comments it sounds like the layout shifts issue specifically are avoided with all |
It's about maximizing the chance that the font is used. This should cover cases like disk cache hit and fast network. Unfortunately, there's no way to ensure an At a more technical level, font preloading (for all For developers, this isn't much more informative than just saying "preloading is good, do that!". So maybe let's not dump that many technical details to developers.
Exactly. |
Got it, great! Thank you so much @xiaochengh ! |
Wow this rabbit hole goes deep. :) A few links I found along the way:
|
Boiling down webfonts and perf.. here's my take:
If I had to characterize the diff between users of Block/swap/fallback all incur layout shifts at the some point in loading. If they didn't chose any If they chose I don't see why we wouldn't recommend preload for all these cases, instead of just optional. Optional has a few special powers, but we'd have to sell people on optional to do that. Two side notes... One, hardly any font-display docs for Two, spending more time looking at all these, I'm increasingly convinced that fallback and optional are superior to block and swap. There is a 100ms difference in "text on the screen" between swap and fallback, but 100ms is nothing. |
Concretely,
|
I think sites that preload all of their fonts (up to 5 or 6) end up less performant than preloading none or just a couple. I think recommending preloading everything would make things worse. |
Well, not every font in their CSS. Just the ones that get used during initial load, which are the ones we flag. Preloading those wouldn't make things worse. |
How can we know with certainty? I've always assumed that more preloading = more contention with other possibly higher priority resources that the browser happens to request just after it sees and acts on the preload directives. |
A blanket rule of fonts that should be preloaded could be "text rendered using webfonts that appears in the viewport during load" would be a somewhat reasonable tip. Of course there's cases where a strapline might not be as important as major headings etc. Still… if it's a non scored audit, then it's still a useful tip. If sites are using more than 3 webfonts/weights/variants, an audit rule to advise them to reduce the number of webfonts would also probably be useful imo. |
I also don't think Lighthouse should tell devs to preload all their fonts.
|
Also @paulirish I just saw
What led you to believe this? From my observations even when the font is already at the exact same depth in the discovery tree such that you would normally never preload it, it still has the effect of the https://melodic-class.glitch.me/font-preload-optional.html If you're referring to the m83 changes having nothing to do with preload, I agree there, but at the very least they inspired the web.dev article and the work here :) |
@patrickhulce and I spent an hour on voice today going through this. There was some contention (lol) on the value of bytes. "Are preloaded font bytes of equal value to renderblocking js/css bytes?" I think yes and Patrick not so much. My POV is that preloaded font bytes will move any webfont-triggered layout shift earlier (which is good) or nullify the need for a shift entirely (also good) and these bytes also carry benefits for the aesthetic fidelity (good). We concluded that we are on opposite sides of one key question: ✨ What is the probability that preloading a font means it makes the cut before the first render? Secondarily, Patrick brought up the 3P Font Provider scenario (aka google fonts), which unfortunately makes this whole preloading thing VERY challenging. This requires further investigation. Perhaps we can find out what % of webfonts are from the 3rd parties (cases where the exact font URL (to preload) is unknowable). We're going to followup on these questions separately to determine if we can broaden our font-preload recommendations. |
This test illustrates the challenges of preloading Google Fonts :/ The font format referenced by Google Fonts stylesheet changes subtly based on the UA with woff to desktop and woff2 to mobile (unclear why?) |
A note: The challenges of preloading with |
Thanks @xiaochengh that's great to know! Perhaps the associated codelab should be updated to follow that style as well then. |
@paulirish given that this work as originally described was completed, would you be comfortable leaving this closed and filing a new issue describing any followup work you wanted to see happen? |
I'm going to go ahead and close this out, but if there is any follow up work that needs to be done here, please feel free to file another issue or reopen. |
Hi there, As it's related to It fails to however recognize link headers or link elements e.g. link rel="preload". Although these are specified, https://web.dev/measure/ continues to return Is this a known issue? |
Starting in Chrome 83, preloaded fonts with
font-display: optional
will result in no FOIT or layout shifts. See https://web.dev/preload-optional-fonts/Lighthouse has two related audits on this:
uses-rel-preload
recommends requests that should be, but currently aren't, preloaded. This is based on a Lantern simulation.font-display
simply points out fonts that don't define afont-display
rule. Our docs suggest they doswap
, but any value passes this audit.To keep this audit simple, I suggest we only look at already preloaded fonts. If a preloaded font is not marked
optional
, the audit suggests making it so to avoid shifts.The alternative would be: basically duplicate/reuse
uses-rel-preload
with a focus on fonts and suggest both preloading AND optional in one go. I think this advice would be too broad, and is certainly more complex. Let's just encourage usage ofoptional
if the developer has already decided to preload a font.That's my pitch. Open to discussion.
The text was updated successfully, but these errors were encountered: