Font Loading Performance 📉 6 Experiments with FOUT & FOIT

  Рет қаралды 13,605

DevTips

DevTips

Күн бұрын

Пікірлер: 62
@sam18b
@sam18b 6 жыл бұрын
The main reason the preload didn't do anything is because your CSS (or more specifically your font definition) is inlined in the head. On a regular site what would happen is you'd hit your page, then you'd load the CSS. Once all the CSS has been loaded only then would the font start loading because CSS only runs once it's been loaded entirely. Using a preload essentially just let's the browser know that we're going to need the font before it figures it out for itself after seeing the CSS
@mvargasmoran
@mvargasmoran 6 жыл бұрын
Damn, thanks for the video, Last Time I had to deal with FOUT/FOIT I ended up self hosting. Then there was still some FOUT and I ended Up covering the screen with a "loading" (nice heartbeat animation) that would run for half a second, and then reveal the site... I Stopped looking at this kind of topics as the improvement was really little for all the hours I pour into it. I guess the best is to have some good defaults that try to match the font the designer wanted.
@OfficialDevTips
@OfficialDevTips 6 жыл бұрын
I like the challenge! It is fun to try and get the load time down. As you can read in the comments there’s a lot of improvements still to be made!
@utyf
@utyf 6 жыл бұрын
Thanks for video. Btw, the 4 approach "with preload script" in your example has WRONG syntax - the SRC is used instead of HREF. Probably that is why you have had no difference. In real app it helps a lot because the fonts are loaded parallel with js bundle (loader indicator is displayed at that time), and then it renders without any FOUT/FOIT.
@OfficialDevTips
@OfficialDevTips 6 жыл бұрын
🤦‍♂️ Hahaha. I feel this REQUIRES a code review follow-up.
@DaxyGamer
@DaxyGamer 2 жыл бұрын
Ironically, the new polymer design on KZbin or the A/B testing tends to make all text flash invisible or unstyled and recommendation thumbnail timestamps take 5 seconds to show up. So it takes 10 seconds for all the content on the homepage to show up.
@charlyecastro
@charlyecastro 6 жыл бұрын
Great vid! You guys should make a video on webRTC!
@OfficialDevTips
@OfficialDevTips 6 жыл бұрын
Yeah great suggestion!
@jonathanbakebwa2292
@jonathanbakebwa2292 6 жыл бұрын
Hi David! What types of functions are these at 12:14 ? I'm kind of self taught, and I never really have interacted with this kind of javascript functions before. I've seen those but never really found a real explanation to why they exist this way. Do I need to use this kind of function syntax, and what makes it so special if I do? Thanks! Now I'll go back to enjoying this scrumptious video... nom nom nom nom....
@funfunfunction
@funfunfunction 6 жыл бұрын
When you put a script tag directly in the HTML, the browser will assume that the rest of the page is dependent on it, and rending etc will stop until the script has been loaded and executed. Sometimes this is what you want, but often not, especially if you are a third party that is offering some code to a developer to paste in. Then you use techniques like the one you see, which inserts a script tag dynamically into the DOM at execution time, which doesn't hold up loading of the page.
@jonathanbakebwa2292
@jonathanbakebwa2292 6 жыл бұрын
@@funfunfunction Wow! Thank you. I didn't know that! Thanks! How I can use this to load cat memes without interfering with my webpage rendering. :D ||| Video Suggestion: Front End Architecture, and how to structure projects.
@sunshineremovalsvic4576
@sunshineremovalsvic4576 6 жыл бұрын
Very interesting but would like to see the review of the preload after substituting href for src. I load in footer from CDN at the moment.
@OfficialDevTips
@OfficialDevTips 6 жыл бұрын
Will do a follow-up with actual working code in all examples 🤪
@sunshineremovalsvic4576
@sunshineremovalsvic4576 6 жыл бұрын
Will try to preload fonts thru cache
@ajinkyachitale89
@ajinkyachitale89 4 жыл бұрын
Which approach is better to use google font for improving the performance of webpage? 1) cdn 2) download (locally)
@gadgetboyplaysmc
@gadgetboyplaysmc 3 жыл бұрын
cdn obviously... You just get that nasty FOUT and FOIT
@danielkirk7350
@danielkirk7350 6 жыл бұрын
Fout is the exact problem that i have with my website on titles. Its already been set up but can't seem to figure out how to mend it. Very frustrating
@cirykpopeye7587
@cirykpopeye7587 6 жыл бұрын
What if you put this website on a webserver? Don't think self-hosted will win anymore as now they're just loading off your SSD. Because the server doesn't load the fonts, the browser does so your latency to your own server is near 0.
@AndyMortimer1
@AndyMortimer1 6 жыл бұрын
Great video, just wondering what the tool is you’re using at the end to run all versions.
@OfficialDevTips
@OfficialDevTips 6 жыл бұрын
I screen recorded them and put them together in a video editing software Final Cut Pro X that I use for editing the videos.
@mattcroat
@mattcroat 6 жыл бұрын
Variable fonts hype!
@RmNrIHRoZSBDQ1AK
@RmNrIHRoZSBDQ1AK 6 жыл бұрын
Font loading is a browser thing, don't mess with it. The problem is that nothing is worse than no text when resources fail to load. Therefore browsers have built-in timeouts for how to handle webfont rendering. You will not increase load speed with JS as you've found out. The only thing you can achieve with JS is avoid any kind of flash but you'll cripple your site by doing so. Or you can use JS to delay loading the fonts even longer, so you get useful stuff on screen first. Self hosted fonts are faster because you're avoiding DNS lookups and TCP handshakes with a different server.
@RmNrIHRoZSBDQ1AK
@RmNrIHRoZSBDQ1AK 6 жыл бұрын
With a cold cache google webfonts seem slower, but in the real world it's quite likely users will have the google's webfont DNS cached already.
@AustroPower
@AustroPower 6 жыл бұрын
Hello David, hello MPJ, Could you guys start some series on Vue.js? Would be great😁. Thank you for all your tips and tutorials. 🙌
@OfficialDevTips
@OfficialDevTips 6 жыл бұрын
Actually it could be interesting. We have no idea how it works.
@thejoker585
@thejoker585 6 жыл бұрын
Can you please explain point-free programming in JavaScript with simple examples (please keep it as simple and as clear as possible)?
@Pikoro09
@Pikoro09 6 жыл бұрын
IMO the page you are using is too small to throw bad results in Lighthouse. It is hard for such a tiny website to be slow. You should have tried it with a bigger site, there you would have seen lower results due to slow font loading.
@OfficialDevTips
@OfficialDevTips 6 жыл бұрын
Youre probably right. Tried having the image to fake weight of the page. It’s difficult because you don’t want to add too much that might influence the metrics but is not related to what you’re actually optimizing.
@sholomaber
@sholomaber 6 жыл бұрын
For the async method you loaded the sync file instead of the async file.
@OfficialDevTips
@OfficialDevTips 6 жыл бұрын
Best code review is publishing a video of your code. Thanks!
@mazwrld
@mazwrld 6 жыл бұрын
Hahaha this was so much fun. I've a question though, in school they thought me not to self host fonts because they take up too much space on a server. Relatively speaking. What's the validity of that?
@OfficialDevTips
@OfficialDevTips 6 жыл бұрын
I’d say none! Check out Zach’s speech linked in the description.
@KeepItFresh02
@KeepItFresh02 6 жыл бұрын
dope. feelin it.
@nendo502
@nendo502 6 жыл бұрын
http2 server push may improve the font load time, worth a try
@OfficialDevTips
@OfficialDevTips 6 жыл бұрын
Woot! Great idea - thanks!
@marcindomanski5654
@marcindomanski5654 6 жыл бұрын
You result may be wrong (or may be not). You tested server cdn vs local font. But in real example the server where is your page can be further and slower that server cdn. You shoul test "server cdn vs server ftp" And what about the situation when yuser browser use font from then cache, because some previous page use that resource?
@OfficialDevTips
@OfficialDevTips 6 жыл бұрын
Regarding cache. I come from the SEO perspective with this - first time you hit the site. And of course, there could be a Google Web Font cached because you visited one before. Regarding server CDN, the browser has a limit on how many resources you can fetch from one domain. If you "shard", i.e. split your resources to other domains you control, you can increase performance because the browser can fetch more resources simultanously. In this example, it is a bit silly because it is so bare though. If you'd make your server support HTTP/2 this is not needed at all.
@LaviYatziv
@LaviYatziv 6 жыл бұрын
Why not just base64 encode the font and embed in the CSS?
@mabdullahsari
@mabdullahsari 6 жыл бұрын
Browser cannot cache it and has to process it each time you reload, very expensive.
@LaviYatziv
@LaviYatziv 6 жыл бұрын
@@mabdullahsarifor a step yeah. But in a spa, or pwa. You should be fine...
@ram-pandey
@ram-pandey 6 жыл бұрын
Is this working this time...? last time we were not able to improve :)
@OfficialDevTips
@OfficialDevTips 6 жыл бұрын
Don't twist the dagger.... It hurts.... 😂
@ram-pandey
@ram-pandey 6 жыл бұрын
@@OfficialDevTips 😂😂
@eswarammajammu1575
@eswarammajammu1575 3 жыл бұрын
I want slipstream let font
@julienjamet
@julienjamet 6 жыл бұрын
I love this music like philip Glass (the first) !
@OfficialDevTips
@OfficialDevTips 6 жыл бұрын
Yeah me too! It was a jazz clip with traditional Swedish music inspirations.
@MarcoBiedermann
@MarcoBiedermann 6 жыл бұрын
Nice Video David. In my opinion your results are not that accurate, since you are running them locally and just emulating the network connection. I would suggest so put your examples up on some hosting platform e.g. GitHub pages and measure al examples using www.webpagetest.org/ This also allows you to run it multiple times and to calculate an average. Also you should moved your CSS to an external file, which might reflect a more real world scenario. I also did quite a lot of research on this topic and I came to the following setup as best strategy. - Host fonts by yourself - Lower file size by using just a subset of glyphs (en only) - Serve font only in woff2, it it supported in pretty much any browser by now - Add "font-display: swap" property to your fontface - Add a preload link to your font-file in the header - Add serif / sans-serif fallback to your font declaration: e.g. "body: { font-family: CUSTOM_FONT, sans-serif; }" - Compress your resources using Gzip (Nginx / Apache module) - Set cache control header (cache fonts for e.g. 1 year) - Add file rev hash to font-filename to allow cache busting This will tell the browser to prefetch all critical fonts, but will render the content on first meaningful paint using your system font and automatically switch to your custom font as soon as loaded. If you would like to make this also work in older browser, yes you would need a shim like FontFaceOberserver but I think this will have a negative impact on modern browsers.
@jsphpndr
@jsphpndr 6 жыл бұрын
Have you tried Bram Stein's Font Face Observer? From my experience it's a much, much better solution.
@OfficialDevTips
@OfficialDevTips 6 жыл бұрын
That is the one I'm using in the video for the two "own font loader" examples.
@jsphpndr
@jsphpndr 6 жыл бұрын
​@@OfficialDevTips Ok. I went back and checked it out. While I do a few things differently, you basically get the same results that I do... This makes me want to test things out again and check if there may be some of these issues. Thanks.
@jsphpndr
@jsphpndr 6 жыл бұрын
​@@OfficialDevTips​, I went back and checked it... fonts start loading and load time are both under a second. I don't know why you're experiencing the delay. I'm curious to try your setup and see what the difference is...
@OfficialDevTips
@OfficialDevTips 6 жыл бұрын
@Joseph Pinder it's available in the description. Now on Friday I'm having a follow-up episode as well, where I try some more techniques and give my verdict on the one and only approach I recommend. (Not the best performing, but best performance vs ease-of-implementation balance.)
@RmFrZQ
@RmFrZQ 6 жыл бұрын
We lurned not to use font loader scwipts. :)
@cashme6819
@cashme6819 6 жыл бұрын
preload the image
@milehighsi
@milehighsi 6 жыл бұрын
I've never had a problem using a font loader with Google's hosted font files. This way you benefit from the very real possibility that a user has loaded the font files (from Google) already, from another site, therefor having it cached. You also get Google's CDN, compression, and the very latest version of the font etc. etc. for free... the main thing is the caching. There is nothing faster than loading from cache. For me this is the main benefit of using Google Fonts. Turing off caching for this entire video is educational but very unrealistic.
@OfficialDevTips
@OfficialDevTips 6 жыл бұрын
Yes if you use the very common fonts everyone else is using (Roboto, Open Sans et al) this is a nice approach. But are you sure you have "never had a problem" when loading your site on a slow mobile 3G connection? Very often the experience is worse than you expect!
@milehighsi
@milehighsi 6 жыл бұрын
@@OfficialDevTips Fortunately the best optimised Google fonts are all amongst the most commonly used. Never may be too strong, admittedly, given that there is no way of testing every device, connection, user prefs combination. However, even if a font isn't cached, if you're careful with your fallback font and styling, there should be very little jank when if it does load late. I've never encountered FOIT on my own sites so I guess that's specifically do with how some people are loading their fonts. It'd be cool if you could get analytics over Google fonts to determine how many people are loading an uncached version. I doubt it would be very many, regardless of your font choice. Every time I look at my wife's screen there's a mad font on there! We as designers/devs don't tend to see the god-awful websites regular people spend their time on..
@milehighsi
@milehighsi 6 жыл бұрын
Specifically regarding painfully slow networks, wouldn't you agree that a more practical solution would be to resist forcing these poor folks to download a custom font?
@OfficialDevTips
@OfficialDevTips 6 жыл бұрын
Haha regarding custom fonts and the "poor folks"! I think we have this amazing tool to use fonts, to create interesting designs. I like it. But by just dropping in the "original", you get poor user experience. Now on Friday I'll publish a follow-up video where I have made up my mind on the best approach where you balance ease of implementation vs performance.
@jobybejoy8219
@jobybejoy8219 6 жыл бұрын
FOuT .?? 🤓
@OfficialDevTips
@OfficialDevTips 6 жыл бұрын
I guess pronunciation should be */faʊt/*
How to Load Web Fonts in 2019 🎆
21:05
DevTips
Рет қаралды 20 М.
Let’s Animate with CSS (and Failing Fast!)
33:28
DevTips
Рет қаралды 20 М.
When you have a very capricious child 😂😘👍
00:16
Like Asiya
Рет қаралды 18 МЛН
IL'HAN - Qalqam | Official Music Video
03:17
Ilhan Ihsanov
Рет қаралды 700 М.
Our favourite ES2018 features 💖
26:04
DevTips
Рет қаралды 22 М.
CSS Animation Optimization and Performance 101
23:13
DesignCourse
Рет қаралды 38 М.
What is THIS in JavaScript?
33:14
DevTips
Рет қаралды 84 М.
Query Parameters in JavaScript (3+1 Ways)
17:18
DevTips
Рет қаралды 19 М.
Optimise your code: load code at the right time
5:11
Chrome for Developers
Рет қаралды 92 М.
Simple Pure CSS Spinners
15:03
Traversy Media
Рет қаралды 68 М.
A 1kb Scroll Animation Library? Hello Scroll-Out
15:20
DesignCourse
Рет қаралды 56 М.