Discussed in #3443915: Font for navigation is preloaded in header even when navigation bar is not loaded
The inter font that is loaded (and preloaded) by the navigation module is huge: 346kb.
Can this be improved? Should we be using a variable font (I'm thinking maybe not). Can we reduce glyphs?
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | cbea4783138c02851f3c601d11defa3e.png | 48.64 KB | finnsky |
| #8 | 7267257719e4e588c7cac16d72e17718.png | 200.91 KB | finnsky |
| #6 | a2c1109b0979f61ece4995733003ef3d.png | 171.23 KB | finnsky |
Comments
Comment #2
ckrinaYou can see the background behind the decision already taken to use Inter font and in its variable form in #3388954: [PLAN] Discuss using Inter font for the navigation. On a design and UI perspective, even on a UX perspective to help give deep and differentiate typography styles, a variable font is the tool we need for a modern UI. It's basically one of the most important UI elements we have, since a UI is mostly built by text and surfaces.
That said, happy to find a way to decrease its weight.
Comment #3
catch@kostyashupenko mentions splitting italic and the different font weights out, and that seems like a good start. Can still ship them and define the rules, but if they're not used by default, they wont be loaded - can also only pre-load what we use by default then.
Comment #4
finnsky commentedImo before that splitting we need to calculate amount of possible benefits.
Cause if we will have lot of font variations this variant (one file for all styles) looks much better.
Even if 3 font types will be used it will be more or less same with that `huge` 346Kb
@catch
this suggestion about different files was made before than Kostia became familar with https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_fonts/Variable_font...
Comment #5
catchThere's a limit to how much text can be shown in the navigation bar at once, how many variations can there be?
Comment #6
finnsky commentedComment #7
finnsky commented@catch for now only 2 types as far as i remember.
so 110kb + 110 Kb against 346Kb
in 2024 ;)
Comment #8
finnsky commentedJust checked we already have 3 types
So this ticket is about ~15Kb overweight.
Comment #9
finnsky commentedArgh. 4 types ;)
So we want to grow assets size here.
Comment #10
catchStill a waste to load the italic variation if it's never going to be used.
The ckeditor team wrote up how they optimized their variable font: https://ckeditor.com/blog/optimize-font-size-with-variable-fonts/ - like separate italic and non-italic variations (where there's apparently no benefit to a single file at all).
Comment #11
finnsky commentedWe don't load italic:
Comment #12
mherchelWhat charsets do we support? Supporting more will obviously result in a larger filesize.
Comment #13
finnsky commentedYes, seems it is one option that we have.
I've checked fonts on websites listed in
https://github.com/rsms/inter?tab=readme-ov-file#notable-projects-using-...
Seems that
https://www.flughafen-zuerich.ch/en/passengers
uses variable font with smaller file-size. Others uses separated files or same file size.
So probably we need to
1. define Languages we want to support https://rsms.me/inter/#languages
2. Check pyftsubset as recommended https://rsms.me/inter/#faq
Comment #14
ckrinaAs Ivan mentions in #11 we aren't aren't shipping the italic font yet (since we don't use it, and I think we won't until the new design system is used more broadly on the UI), so that's something we can't remove.
So I agree with him on that the only way to decrease the file size: removing initial Language support to split the glyphs in different subsets. Do we have any guideline for Language prioritization already?
Comment #15
jponch commentedI could do some tests to see if we could, perhaps, eliminate one of those weights and get it down to 3 weights without greatly affecting the overall visual hierarchy. I'm not certain if limiting to 3 weights would make that significant of a difference? I'd be open to testing though if you think it's worthwhile.
Comment #16
catchI think it's worth knowing the answer to #15 even if it turns out to be a dead-end.
In general thanks for the answers above, it's good to know the low hanging fruit are covered even if that means there's not much low hanging fruit to get things down under 300kb...
Splitting by glyphs sounds like it could reduce size a lot, and in general single users don't load lots and lots of different languages that much even if sites have them - so duplication would be less of an issue than other ways of splitting. However, I have no idea how to split a font by language/glyphs - we wouldn't want to arbitrarily remove support for various languages since in theory we support anything, so it'd be a case of taking them out by default but adding them back when needed?
Related to this has anyone tested what happens with this font and CJK languages, arabic, farsi?
Comment #17
ckrinaRe to #15 and #16:
We're using a variable font: it means that all weights are built in one file, so it really doesn't matter if we use 1 weight or 4. That's the magic behind variable fonts and why we decided using them. A variable font size might be twice a regular font, but you get way more :)
So there is no need for any redesign/design exploration. But thanks @jponch for being open to it!
There are several tools out there. @finnsky 's links have a few of them. But the question still is which languages.
About other languages, then it defaults to the system's font. I've tried it with Arabic and Japanese.
Comment #18
catchHad a look at Mercury's font situation, it also uses Inter.
Mercury isn't using a variable font (but probably could/should), however it is splitting the glyphs - they're added back via separate CSS declarations using
unicode-range(https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/unicode-range) which answers #16. This is done for cyrillic, greek, and vietnamese.So I think for Navigation, splitting the variable font by glyphs then adding them back with unicode-range might end up being the most efficient. Visually it would end up exactly the same, a smaller default font size for everyone, an extra file for pages that need extra glyphs.