-
Notifications
You must be signed in to change notification settings - Fork 27.3k
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
[Font Optimization] Asynchronous non-critical font styles #16065
Comments
@joe-bell thanks for the feedback, highly appreciate the interest. I did investigate the approach you mentioned. However there are some pitfalls to the same.
Let me know if there are alternate findings |
@prateekbh thanks for the detailed feedback here, it's helpful to understand how this plays apart in the Core Web Vitals work! More and more people are choosing to use I would really recommend taking a look at this recent article by @csswizardry; "The Fastest Google Fonts". It does a good job of explaining how important this feature would be |
Thanks for the links @joe-bell. I'll address the concerns in the following points
I completely agree with this and don't wanna encourage otherwise. I just mentioned it for completeness sake.
Note: I agree that there might be a use case where someone would want to use async css to load fonts and I would still recommend component like |
@prateekbh gotcha, thanks for taking the time to writing this up I think I agree in this case that making this the default option is not a good idea. However, what approach would you suggest to make sure people who are using Do you still think it's viable to have this async feature available for those using |
Well choosing I would suggest people to opt for the async css when they are very sure that fonts are of least interest but not something to come out of the box, given that if you're adding a font in the first place you might want it to load faster as well than later. |
As a small sidetrack: if I want to use <link rel="preload" href="https://..." as="style" onload="this.onload=null;this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="https://...></noscript> to make loading CSS async, that does not work because I'd have to rework that to using onLoad with a function, but that function is never executed. So
|
Hey @willemmulder, I think this might be useful to add over at #12984 |
Use what is currently the best workflow for importing variable web fonts from the Google Fonts API: - https://css-tricks.com/how-to-load-fonts-in-a-way-that-fights-fout-and-makes-lighthouse-happy/ - https://csswizardry.com/2020/05/the-fastest-google-fonts/ Perhaps in the future I'll look into self-hosting fonts, but Google Fonts is nice because Chrome and other browsers are able to cache the responses and reuse them across websites. Related to: vercel/next.js#16065
Use what is currently the best workflow for importing variable web fonts from the Google Fonts API: - https://css-tricks.com/how-to-load-fonts-in-a-way-that-fights-fout-and-makes-lighthouse-happy/ - https://csswizardry.com/2020/05/the-fastest-google-fonts/ Perhaps in the future I'll look into self-hosting fonts, but Google Fonts is nice because Chrome and other browsers are able to cache the responses and reuse them across websites. Related to: vercel/next.js#16065
Just tried out "Automatic Webfont Optimization" in Thanks for the cracking discussion ✌️ |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Feature request
Whilst I hugely appreciate @prateekbh's work to enhance the external font loading experience, it would be nice to support (or maybe even make default) the option to treat these font styles as non-critical.
RE: #14746, #16031
Describe the solution you'd like
An
async
option could be defined in the experimental config (but I would argue it might be best to assume that font styles are non-critical and set this totrue
by default) which would extract the external CSS into a separate CSS file.This CSS file would be referenced in the head, and set to
media="print"
on initial load then tomedia="all"
on app hydration. With lots of modern CSS-in-JS libraries extracting to critical CSS, this would avoid clashing opinions on what should actually by considered crticial.Describe alternatives you've considered
I built and maintain
next-google-fonts
but this doesn't extract CSS at compile time; it just asynchronously loads Google Fonts.Additional context
Again, thanks so much for your work on this @prateekbh. Happy to help out where I can
The text was updated successfully, but these errors were encountered: