Okay, we can get into the minimization strategies now, and I'm going to explain the FOUT and FOID in better detail and you'll see what they mean. First and foremost, just don't use a web font. It's not really a tip, I know, but I had to mention it. Yeah, if, for example, your page is not, if it's not necessarily for you to use a font, just don't use a font, right? There are beautiful system fonts out there who do not cost CLS. So do yourself a favor, just don't use a web font if you don't really need to, so you can avoid all of the upcoming tips that I'm going to give you, just don't care about them.
And I like this website at the bottom, Modern Font Stacks, because it is a website that showcases 15 different font combinations of built-in fonts that do not cost CLS, but you can just copy paste them. You can just copy paste the font family, I don't know, set it as a CSS variable, use it. You're going to be sure that your pages are not going to have any CLS, it's gonna be zero, which is good. So that is tip number one, if you really don't need to use a web font, just don't use a web font.
Tip number two, host your own web fonts. So it might be easier importing Google Fonts, and there's a research from the HTTP archive that shows like 80% of web pages in this world use a web font, right? So, which means that those 80% of the pages do have CLS, and 65% of them use Google Fonts. I know, it's easier, right? You just copy paste CSS import, you put it in your app and then you have fonts, right? But there are negatives to that and there's also positives on why you should host your own fonts.
And it's not as complex as it seem, like hosting your own fonts. You don't need to spin up a CDN network just to host your own fonts. The number one benefit is that the browser avoids another HTTP round trip because you don't really have a connection to your server, right? It started downloading your websites files. It reached a point where it needs to download the CSS fonts. So there's a branch over here, right? If you're using a Google font, it needs to make another HTTP round trip to authenticate with the Google servers. I think it was like the G-Static servers or something like that. The CDN because it hasn't opened a new connection up until this point, yeah? And that costs, right? It's a whole new HTTP round trip. But if you keep them at your server, it's not gonna do that, it's just going to download the fonts and it'll cache them locally in the browser. And also another benefit is that you don't really need to depend on the availability of the third-party service. Now, okay, yeah, Google Fonts, they don't have any issues with the availability, right? But there are websites and 35% of all the websites who use a web font exactly, they don't use Google Fonts. They use something else. And the availability of that service to serve the fonts to your website, you can't really guarantee that, right? So that's why hosting your own fonts is better. And again, using less font files is another tip. So when you load different weights and when you load different styles, like bold, italic, italic bold, et cetera, you're basically loading a font file, an actual font file for each of them, right? So if you have a regular, a bold and italic version, that's like three files. So the browser will need to download those three files. What you should know is that the browser is also capable of mimicking the weight and style of the font. It's not always going to be correct, just like the font intended to, so it varies. But it's a good idea to check if the full bold, or the fake bold and the fake italic look good enough before you actually import them.
Comments