Repository navigation
Fonts API: the optimized sans-serif fallback only matches Arial, so Android and Linux get none #1471
Replies: 2 comments
|
That's surprising. IIRC Arial is the most available sans serif font (~99%, there's a site for that I dont recall). I'm cautious about adding more fallbacks because that can create quite more css. So to be clear I'm not opposed but I wanna make sure this is the right solution |
|
Fair to check. I think the ~99% is a desktop figure (the font-stack sites I know survey Windows and macOS), and on those Arial really is everywhere. The gap is Linux and Android, and it's narrower than "no Arial": the issue is that I tested it on Chromium 156 on Debian 13, with fonts-liberation and fonts-croscore installed, so
So Android works the same way on paper. AOSP's fonts.xml has On the CSS: each extra fallback is one |
Uh oh!
There was an error while loading. Please reload this page.
Summary
The Fonts API's optimized fallback for
sans-serifmeasures against Arial alone, so it does nothing on devices without Arial, which includes every Android phone and most Linux desktops and CI runners. Adding Arimo and Roboto to thesans-seriflist would cover those, at the cost of a few bytes of CSS.Background & Motivation
We found this chasing a Largest Contentful Paint regression on our site's blog index (conn3x.org). Our config is the documented pattern:
The last entry is a generic family, so
optimize-fallbacks.tsasksRealSystemFallbacksProvider.getLocalFonts("sans-serif", …), which returns['Arial'](DEFAULT_FALLBACKS['sans-serif']insystem-fallbacks-provider.ts). The generated face is:On a device with no Arial,
local("Arial")matches nothing, the stack falls through to plainsystem-ui, and the swap to the web font changes the text's size. On Lighthouse's mobile run, from headless Chrome on Linux, that swap became our page's largest paint. First paint was at 0.9 s and LCP at 1.96 s, with 77% of it render delay, and the LCP element was text, not an image.system-uialready has a richer list (BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial), but you only get it ifsystem-uiis the last fallback. The docs' examples end insans-serif, as most configs will.Goals
sans-serif, and so the default, produces a metric-matched fallback on Android and Linux as well as macOS and Windows.Example
Extend the list and the metrics table:
entireMetricsCollection.jsonwith exactly Arial's metrics (ascent 1854, descent -434, lineGap 67, unitsPerEm 2048, xWidthAvg 913). It's ChromeOS's Arial substitute, and Debian ships it infonts-croscore(/usr/share/fonts/truetype/croscore/Arimo-*.ttf). Its overrides would equal Arial's, so it's a secondlocal()for the same numbers.SYSTEM_METRICSfor thesystem-uilist, and it's Android's default sans.ui-sans-serifcould get the same. Liberation Sans is the other common Linux Arial substitute, but capsize doesn't list it, so I've left it out rather than guess its numbers.I'm happy to send a PR with a changeset and a test against
optimizeFallbacksif this direction is welcome. I didn't want to open one without checking first, since it adds faces to every site that usessans-serif.All reactions