How to Load Fonts in a Way That Fights FOUT and Makes Lighthouse Happy
css-tricks.com
css-tricks.com
I'm a fan of the native font stack approach [1] that Bootstrap now uses, and is used by Wordpress and Medium. The idea is to have a long font stack that opts for the operating system font (like Segue UI for Windows, San Francisco for Mac, Roboto for Android, etc.), which is modernly beautiful, loads instantly, and fits with the users' native application.
On a personal site I added a custom font that weighs a whopping 11kb to give it a very different feel.
When I first used the native font stack for a new website I set up [1], I was surprised that it looks very nice on all devices! Without any additional network requests or CSS hacks to load the fonts.
But oh my god, it’s so complex! I wish the platform (http/HTML/css) could support this natively without any need for javascript or tricks of any sort. Some of it looks like irreducible complexity: particularly “choosing a fallback font that closely matches the size and style of the eventual font”. The platform can’t do that for you. But surely a “sufficiently advanced” HTML/css will be just a little wiser and let you say, with one well placed keyword, “this is the font I want to use, but don’t wait for it, use it once it’s available and use this one in the meantime.”
(And I’m thinking that inlining the fonts as base64 encoded stuff might be more optimum and prevent stuff moving around. It’s such a tiny point, I don’t think engineers everywhere in the world should all have to spend effort on this.)
As for using a fallback font that closely matches to minimize the impact of the switch over, how realistic is that? In the demo I felt the fallback font looked very different from the final font (in weight, style and size) and I'm wondering if it's because I'm on Android and the author chose fallbacks that only match on their OS?
It would a lot more realistic if browsers other than Firefox supported font-size-adjust, which allows the fallback font to mimic the metrics of your primary font.
Here's an article from 2010 that describes how it works: https://webdesignernotebook.com/css/the-little-known-font-si...
Here's a site of mine which loads some fonts.[1] See any loading delays?
It's junk-free. No trackers, no ads, no "Google Tag Manager".
> It’s important to note that self-hosting the fonts might also help fix render-blocking issues
Interestingly, your fonts loaded quickly, but I got wildly varying results when looking at your site - for example it took me six seconds to download your 8kb background jpg on one load.
But you don't have to use it, and yes for some reason that seems to be a lost art.
Furthermore, Google Font subsets their fonts so that if you only use English, the other parts of the font that contain Greek, etc. won't load (via unicode-range CSS)
It looked strange for about thirty minutes. After that: I'm not going back.
Everything is faster, everything looks sane. The few sites where custom fonts are an integral part of the value? I'm willing to re-activate fonts for those. Happens almost never.
Only "problem" is that icon fonts are blocked (hamburger menus, thumbs up buttons), but I can live with that (and if it's too difficult to use, I may also re-activate fonts temporarily).
The system font stack is probably the best though.
And even after this it seemed really inconsistent whether it would wait to display the correct font or load the fallback font then visually hot swap in the correct one depending on the browser and the device used.
This is exactly what the article is arguing against, that the content is the most important and it should show immediately, no matter if the font is yet available or not.
> Why not use font-display: swap instead?
That's again exactly what the article is advising people to do. Another action that the article suggests, boils down to "choose a default font that is similar to your custom one, to minimize the effect of FOUT", how does that decrease the value for the users?
I'm not sure if you either read the article then decided to write your comment pretending you didn't, or if you're just rehashing what the article just said for some other purpose.