Current section: Code Splitting 33 exercises
solution

Eager Loading

Loading solution

Transcript

00:00 All right, here's our loadGlobe function that we passed to Lazy. Now, we could call this loadGlobe function anytime we like, and it makes sense to call it onFocus. So, onFocus, loadGlobe. Yep, and onPointer, enter.

00:17 Oh, not cancel, but enter. There we go, loadGlobe. So, once the pointer is entered, or once the focus has been received on the checkbox, then we can load the globe. So, with an empty cache and a slow 3G, I'm going to hover over it,

00:35 and you'll notice that we already started loading the globe code. So, by the time I get around to actually clicking on it, most of that module code is already ready, and my loading is not going to take nearly as long because we already started loading that UI. Now, hopefully, your user isn't on such a slow network that it's even that slow,

00:53 but at least we can start loading the globe a lot faster. Lots of users are not going to be hanging around the checkbox for quite that long either. This is just a little bit of a faster user experience for people as they're navigating around your application. So, just a little bit of eager loading there.