Open neobutter opened 4 months ago
Hey there, @neobutter! I'm Dosu, a bot here to help you with bugs, questions, and becoming a contributor. Let me know how I can assist you! 🤖
The issue of WOFF fonts being downloaded instead of WOFF2 fonts in your Nuxt project can be fixed by ensuring that the font sources are correctly specified as WOFF2 in your configuration. From your provided CSS, it appears that the @font-face
rules are correctly specifying WOFF2 fonts with unicode-range
.
However, the presence of WOFF fonts without unicode-range
might be causing the browser to prioritize them. To ensure WOFF2 fonts are prioritized, you can explicitly specify the WOFF2 format first and ensure that WOFF fonts are not included unless necessary.
Here is an example of how you can structure your @font-face
rules to prioritize WOFF2:
@font-face {
font-family: 'Roboto';
src: local("Roboto Regular Italic"), local("Roboto Italic"), url(/_fonts/KFOkCnqEu92Fr1Mu51xFIzIXKMnyrYk-0OGiuKW0Qv.woff2) format('woff2');
font-display: swap;
unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
font-weight: 400;
font-style: italic;
}
/* Repeat for other unicode ranges and styles */
Ensure that all your @font-face
rules prioritize WOFF2 and avoid including WOFF formats unless absolutely necessary. This should help the browser to load WOFF2 fonts first.
Additionally, you can check your Nuxt configuration to ensure that it is set up to prioritize WOFF2 fonts. Here is an example configuration:
export default defineNuxtConfig({
modules: ['@nuxt/fonts'],
fonts: {
families: [
{ name: 'Roboto', src: '/path-to-roboto.woff2' },
// Add other fonts as needed
],
},
});
By ensuring that your configuration and CSS prioritize WOFF2 formats, you can resolve the issue of WOFF fonts being downloaded instead of WOFF2 fonts [1].
To continue talking to Dosu, mention @dosu.
I still don't get this. I want to include woff2 and woff, but somehow in my @font-face
it puts the woff before the woff2. So woff to is prioritised now instead of woff2.
@font-face {
font-family: Lufga;
src: url(/fonts/custom-thin.woff) format(woff),
url(/fonts/custom-thin.woff2) format(woff2);
font-display: swap;
font-weight: 100;
font-style: normal;
}
@font-face {
font-family: Lufga;
src: url(/fonts/custom-extra-light-italic.woff) format(woff),
url(/fonts/custom-extra-light-italic.woff2) format(woff2);
font-display: swap;
font-weight: 200;
font-style: italic;
}
/* ... */
Why isn't this automatically done?
@stijns96 Would you provide a reproduction, please? 🙏 I take it you're using the local provider?
let's track the wrong woff2 priority in https://github.com/nuxt/fonts/issues/135 - now resolved in https://github.com/nuxt/fonts/commit/b087d47ec514f72820109cfdb0bf833480fde7d7.
... and leave this issue to track woff2 not being loaded due to unicodeRange
.
Is there a fix for this?
The browsers ends up loading a 66 KB woff font for me, instead of an 8 KB woff2. This module does more harm than good for optimization (for those who do not check). 😢
would you be happy with only the woff2 font being loaded?
would you be happy with only the woff2 font being loaded?
I can't speak for everyone. But for my projects, woff2 is all I need. I appreciate the work on this. Didn't mean to sound direct. Just not sure if people check the size of what is being served, and bandwidth is expensive. Thank you for all you do fot Nuxt! 🍻
Hi @danielroe ,
I think I rather only load woff2 and use a fallback font, then loading woff.
But that some personal preference
Also, Things seem to work better with fontsource as the provider, instead of google. At least I get the correct subset and format loaded.
🍻
I created a simple example from the official site of Nuxt font.
https://stackblitz.com/~/github.com/neobutter/nuxt-font-woff2
If you run this project, you will see that you are downloading WOFF fonts, not WOFF2 fonts.
As far as I analyzed, the generated css file has unicode-range set for woff2 fonts, but not for woff fonts. (This can also be checked via Nuxt dev tools).
My guess is that woff doesn't have unicode-range, so it loaded woff fonts instead of woff2.
I'm currently working on a project, and this issue prevented me from using this module. (I used google-fonts (https://google-fonts.nuxtjs.org/).
If this is a bug, I would appreciate a fix.
(I am not a native English language speaker, please forgive me if I was rude).