Under Construction
Backend••12 min•74 views••

How are lazy loading and preloading different?

Minh Khoa

Minh Khoa

Author

image.pngA Shop screen has dozens of item images. The game can wait until the player opens the Shop to load them, or proactively load them before the player needs to use them.

Lazy loading loads on demand. Preloading loads before the expected need. These two approaches change when the work is done and when the user has to wait.

Lazy loading — open the Shop first, then load

When entering the lobby, the game only loads the resources needed for the lobby. Only when the player presses Shop does the game start loading the shop images and display a loading state while waiting.

If the player goes straight into a match, the Shop’s separate resources do not need to be loaded yet. This reduces work during startup and avoids keeping resources around early that may never be used. The trade-off comes on the first time the Shop is opened, when the player’s action must wait for loading to finish. MDN — Lazy loading

If the game keeps the images after the Shop is closed, the next open may be faster. That also depends on whether the resources are still kept or have already been released.

Preloading — preparing resources before opening the Shop

Suppose that after completing the tutorial, the player is guided to buy the first item. The game can start loading the necessary images while the tutorial summary screen is displayed.

If loading finishes before the player presses Shop and the resources are still kept ready, the shop screen can use them immediately. The loading wait time has been shifted to an earlier stage. If the player opens the Shop too early, the game still has to wait for the remaining load. Godot — Background loading

Preloading uses resources earlier. It can consume memory, bandwidth, or processing time while the player is doing something else. If they skip the Shop, the preloading work may not bring any benefit in that play session.

Comparison pointLazy loadingPreloading
When loading startsWhen the need appearsBefore the expected time of use
The first openMay have to wait for loadingReduces waiting if the resources are already ready
Initial costDelays parts that are not yet neededPerforms part of the work earlier
Suitable forContent that is opened infrequently or is hard to predictContent that is likely to be used soon

You can combine both in the same screen. With the Shop, the game preloads the images for the items on the first page, then lazy-load the next pages as the player scrolls to them. That way, the first open has enough content to display without needing to load the entire catalog.

When measuring effectiveness, check the time from pressing Shop until interaction is possible, as well as memory before opening the Shop. Even after resources are loaded, they still need to be brought into the interface and rendered before the player can see them.