Lazy loading | Shreya

Post

editor-img
Shreya
Oct 9, 2022

Lazy loading

Lazy loading means that a component or a part of code must get loaded when it is required.

It is also referred to as code splitting and data fetching.

media

In React, it bundles the complete code and deploys all of it at the same time. Now, usually, that's not a bad idea, since React SPAs (Single page application) are quite small and do not affect the performance.

But what if we have a gigantic application, like a content management system with a customer portal, admin portal etc. In such a case, it does not seem like a smart idea to load the complete application.

It will be a huge application and will cost a lot of unnecessary data transfer which can lead to slow loading of the website.

A customer login, will not have access to admin specific features, so loading it is a waste of memory and time.

The benefits of lazy loading include:

Reduces initial load time – Lazy loading a webpage reduces page weight, allowing for a quicker page load time.

Bandwidth conservation – Lazy loading conserves bandwidth by delivering content to users only if it’s requested.

System resource conservation – Lazy loading conserves both server and client resources, because only some of the images, JavaScript and other code actually needs to be rendered or executed.