DEV Community

Discussion on: Explain Lazy and Eager Loading Like I'm Five

Collapse
 
ryan profile image
Ryan

Your friend is coming over to play.

Eager Loading: You open the toybox and pull all the toys out.
Lazy Loading: You leave the toybox alone until your friend arrives.

When should we use them?

Eager Loading: You open the toybox and pull out the toys you know you are going to play with. Your friend arrives and you start playing right away.

Lazy Loading: You aren't sure what your friend wants to play, so you wait for her to arrive.

When should we not use them?

Eager Loading: You open the toybox and pull out every toy just in case you will play with it. Your friend rings the doorbell. You can't answer because you're still pulling out toys. Eventually you answer the door after she's been waiting a while and let her in. When she leaves you have unused toys all over the floor.

Lazy Loading: Your friend's favorite toy is your cowboy figure. But you don't like it, so it's buried at the bottom of the box. Your friend arrives and wants to play with the cowboy. She has to wait for you while you dig through the toy box to find it.