Nuxt UI / Nuxt Fonts generating duplicate font-face rules
"@nuxt/ui": "^4.0.0",Here's my config: Looking at my entry bundle, I see pairs of @font-faces like this: Any idea?
3 Replies
Hi @hiimmox. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
The duplicate
@font-face rules you are seeing are expected behavior when using Nuxt Fonts with providers like Google Fonts. Nuxt Fonts generates multiple @font-face rules for the same font, weight, and style, but with different unicode-range values. This is how Google Fonts (and other providers) optimize font loading: by splitting the font files into subsets for different Unicode ranges, browsers only download the subset they need for the characters on the page. This reduces the overall font payload and improves performance.
For example, you might see two (or more) @font-face rules for Figtree at weight 400, each with a different unicode-range and a different .woff2 file. This is not a bug or a misconfiguration—it's an intentional optimization.
From the Nuxt Fonts documentation:
We'll generate rules to point your browser to the right source files. They'll be injected into the same CSS where you use the font-family... plus more font-face declarations for other unicode ranges/weights
>
[Nuxt Fonts processes all your CSS and does the following things automatically when it encounters a font-family declaration...]>
1. Generates and injects>@font-facerules for you. We'll generate rules to point your browser to the right source files. They'll be injected into the same CSS where you use thefont-family. 2. Proxies and caches font requests. Rather than using the original source URLs (to remote servers), we generate rewrites under the/_fontssubpath. When accessed by your browser, we download the font from the remote server and cache it locally. 3. Include fonts in build. When you build your project, we'll copy across all the fonts used in your project so you don't need to make any external requests when loading your site. (Any that haven't already been cached in development are downloaded at build time.) Font file names are hashed and Nuxt will serve them with long-lived cache headers.
Read moreSo, unless you are seeing truly identical
@font-face rules (same unicode-range, same src), this is normal and beneficial. If you are seeing exact duplicates (not just different unicode ranges), that could indicate a bug, but based on your example, this is standard font subsetting behavior and not an error.
If you want to further customize or reduce the number of subsets, you can adjust the subsets option in your config, but for most use cases, the default behavior is optimal for performance and compatibility.
How Nuxt Fonts works
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@327193365797928963> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
TIL!