Current section: Code Splitting 33 exercises
Problem

Eager Loading

Loading exercise

Transcript

00:00 One thing that I'm not super jazzed about is if I'm on a slow 3G network, and this is the first time I've ever loaded this before. So here, let's let's speed this up. We'll do a full page refresh with no cache and everything. And then we close this out. Slow 3G network. If I show the globe, I'm like sitting here. I'm ready to show the globe. Awesome. Boom.

00:19 I click it. It's kind of annoying, right, to have to wait that long. Like it would. This is one of the things we traded off by having the full app load faster is that now our interactions are going to load slower. That's kind of that doesn't sit well with me. I would like these things to load, you know, faster. Just make everything faster.

00:38 And so what we could do is we could just say, hey, if the pointer has entered this checkbox or if this checkbox has received focus, then go ahead and start loading the globe. And the cool thing is that it doesn't matter how many times you call that dynamic import, you call it once and then the module is going to get retrieved. And if you call it again, the browser is going to be like, oh, this is already in my cache and it's fine.

00:59 It's not going to trigger another network request or anything. The browser is pretty good at handling those. And so we could actually just eagerly load this globe by calling that dynamic import. And if we do that, then on focus and on pointer enter, then maybe the global load, at least a little bit faster. Even if they're really fast, it's going to be like 200 milliseconds

01:20 or even more that will be faster. And, you know, that that does make an impact. So why don't you do that?