-
Notifications
You must be signed in to change notification settings - Fork 27.1k
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 optimizations #14746
Font optimizations #14746
Conversation
…ocess-optimization
This adds ncc inlining optimizations for the following dependencies: * cacache * schema-utils * find-cache-dir * mkdirp * neo-async * web-vitals The slight increase in output in the reports here is due to the variation of the bundled version of web-vitals. In addition, this moves ast-types to be a devDependencies entry instead of in dependencies as it was before vercel#14746 as I could not see any production usage (ping @prateekbh). Happy to separate that out into a separate PR if preferred too.
is there any documentation about this feature? |
Does this work yet? If I add a link tag to Google Fonts in _document Head, I see it outputted as is, without any optimizations. Note: when I try to set the Vercel build command to |
Actually i didn't realize that, finally i just installed the fonts i wanted and it solved the problem. |
@SalahAdDin we do plan to add documentation when landing this as stable out of experimental |
@SalahAdDin could you explain briefly what exactly you mean by "I installed the fonts?" - I am also curious about this feature as font loading takes quite some time. |
@FBosler I installed the fonts from fontsource:
|
@SalahAdDin thx! That’s pretty cool, didn’t know about it. So does this still make use of the fontOptimization? Cheers! |
I use this instead of font optimization, i don't know if it does work or not. |
Hey, @prateekbh! How are you doing? This feature is available in Next version 10.0.1? How can I use this? |
Hi there, I looked at the related links and found an example made by @ivoberger in ivoberger/ivoberger.com@08186a3 |
This should be out of and experimental flags but might not work with react's new JSX. That is a WIP. // @Timer for more accurate info |
I'm not sure if that was an announcement that this is out of experimental, or if it's saying that taking it out of experimental is delayed because of react's new JSX. What is the current state of this? Does it still require the experimental flag? Is there any additional documentation? |
I am also confused about the state of this functionality, it seems not yet documented but activated by default? |
In general, if any feature starts as experimental, you can consider it "shipped" once docs land. Further, there will be a release and corresponding blog post that outlines the new feature. We are working on a new Next.js release, which will provide more guidance on this feature. Stay tuned! |
@leerob I know thats why I am confused about this feature not been mentioned in the docs :-) Basically I was using the Next-Google-Font package and with this feature I have the feeling that both approaches are interfere with each other and I'd like to turn it off. |
You will not need |
@leerob I'm using Google fonts by its npm package directly, what's about it? |
@SalahAdDin we will provide guidance when this feature is released. For now, no action is needed. Thanks! |
hi, the automatic fonts optimization landed in next 10.2.0 as stable. where can I found the docs? I can't find more than this blog post (https://nextjs.org/blog/next-10-2#automatic-webfont-optimization) and just putting the example <style data-href="https://fonts.googleapis.com/css2?family=Inter">
@font-face{font-family:'Inter';font-style:normal}
</style> |
Hello Richard, the |
thanks for the quick reply. and I was just able to find this: https://github.com/vercel/next.js/pull/24572/files |
Very useful, but unfortunately it is not available on public documentation yet. |
Description
This PR introduces a new experimental flag
optimizeFonts
. With this flag turned on, we will grab the<link rel='stylesheet' href='https://fonts.googleapis.com/...'/>
(List of font providers to be extended in future PRs) tags and inline it's content. This eliminates the extra round trip that the browser has to make to fetch the font declarations. This helps in faster paints and improved LCP.Design
The functionality is broken into two parts
<link rel='stylesheet' href='https://fonts.googleapis.com/...'/>
tags and downloading their content at build time.In order to do the above-said we use.
<link rel=stylesheet href='https://fonts.google.com/css...'>
in 1P code's AST and download their content infont-manifest.json
._document.tsx
,Next/Head
makes these<link rel=stylesheet href='https://fonts.google.com/css...'>
inert by switching them todata-href
. This can also be done at render/serve time butNext/Head
goes and re-renders it tohref
at client side. This results in double download of the same content.PostProcessing
step that adds a new style tag for every<link>
tag encountered and inline its content.Note
Making the experimental flag available at all places adds some complexity to the PR. These pieces will be cleaned whenever the flag will be removed