SlideShare a Scribd company logo
A Complete
Tutorial on
Lazy Loading
in Angular v11
www.bacancytechnology.com
Table of Index
1. Introduction
2. What is Lazy Loading in Angular?
3. Why we need Lazy Loading in Angular?
4. Angular lazy loading example: Steps to
implement Lazy Loading
5. Watch it being lazily load
6. How to verify Lazy Loading in Angular?
7. Conclusion
Introduction
We have already discussed Angular routing in
Angular v11 in the previous blog. In which I
have provided a step-by-step guide for Basic
Angular Routing and Nested Routing with
params with Github repository. Before
learning about Lazy Loading in Angular, I
would suggest you to go through that for
revising the fundamentals.
So, let’s be enthusiastic about implementing
and learning Angular Lazy Loading!
What is Lazy
Loading in
Angular?
In case you have worked with any front-end
frameworks, then you might have heard the
term Lazy Loading. The idea behind it is
similar irrespective of various frameworks.
Lazy loading is a technique that permits you
to load the javascript components only when
their respective routes are active or being hit.
It increases the performance and speed of the
application by splitting the app into various
bundles. As per the user navigation, bundles
are being loaded as required.
Why we
need Lazy
Loading?
Sometimes we want to load only those routes
whose UI is being displayed. For example, if
I’m on the Home page right now, I would not
prefer to load the Marvel Movies page and DC
Movies page.
You might not understand the advantage of
lazy loading in the website having few pages.
Still, this technique will create a more
significant difference in performance when
the application is quite large. For that
purpose, I would rather lazily load the
components.
Angular lazy
loading
example:
Steps to
implement
Lazy Loading
Here’s the Github repository where you can
find the source code.
Create a module and separate routing file
named lazy-loading. The purpose of
independent routing is to handle all the
components associated with angular lazy-
loading module.
ng g m lazy-loading --routing
Create a module and
separate routing file
Create a component named lazy-demo within
the lazy-loading module
ng g c lazy-demo
We will be adding a link in the header on
whose route we will implement lazy loading.
app.component.html
<li class="nav-item">
<a class="nav-link" [routerLink]="['/lazy-
loading']">
Lazy Loading
</a>
</li>
Create a component
Adding Link to Header
Now, we will lazily load the component,
which will be displayed on the route – /lazy-
loading
Make necessary changes in app-
routing.module.ts.
Here we will load the module lazily using
loadChildren
app-routing.module.ts
{
path: 'lazy-loading',
loadChildren: () => import('./lazy-
loading/lazy-loading.module')
.then(m => m.LazyLoadingModule)
},
Lazy Loading with
loadChildren
It’s time to set up the route in lazy-loading-
routing.module.ts.
lazy-loading-routing.module.ts
Setting up the route
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from
'@angular/router';
import { LazyDemoComponent } from './lazy-
demo/lazy-demo.component';
const routes: Routes = [
{ path: '', component: LazyDemoComponent }
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class LazyLoadingRoutingModule { }
Watch it being
lazily load
Thus, we have seen the steps for
implementing Lazy loading in Angular. After
following the instructions, you’ll see
something similar to this (excluding CSS and
text)-
Video URL:
https://www.bacancytechnology.com/blog/w
p-content/uploads/2021/03/video.mp4?_=1
You will observe that main.js is being served
on refreshing the browser. And the Lazy
Loading module is loaded only on hitting the
route /lazy-loading.
How to verify
Lazy loading in
Angular?
The video mentioned above is proof that Lazy
loading is working fine. But here are other
ways to verify the implemented lazy loading
in Angular.
Run the following command to generate
build-
npm run build
And you’ll notice something like this –
The above image verifies that a separate
chunk is generated for the lazy loading
module.
Another way to verify is to open the dist
folder of your project. There you will notice a
separate file for the module which uses Lazy
Loading. Below is the reference image –
Step by Step Guide on Lazy Loading in Angular 11
So, this was about implementing Lazy loading
in Angular from scratch. Many developers
choose ngx-loadable for implementing lazy
loading in an existing Angular application. If
you don’t have an idea regarding it, you can
visit this blog- Implement Lazy loading in
Angular Web app using ngx-loadable.
Despite providing solutions, it is challenging
to follow steps when dealing with large-scale
applications or decrease production build size
by benefiting from Lazy Loading. At such
times, it’s beneficial to take help from
experts. If you are looking for a helping hand,
contact Bacancy Technology and hire Angular
developer having experience and expertise in
Angular web development.
Conclusion
Thank You
www.bacancytechnology.com

More Related Content

PPTX
Angular Lazy Loading and Resolve (Route Resolver)
PPT
Angular 8
PPTX
CSharp Presentation
PDF
Angular 16 – the rise of Signals
PPTX
Sharing Data Between Angular Components
PDF
Lets make a better react form
PPTX
Introduction to angular with a simple but complete project
ODP
Routing & Navigating Pages in Angular 2
Angular Lazy Loading and Resolve (Route Resolver)
Angular 8
CSharp Presentation
Angular 16 – the rise of Signals
Sharing Data Between Angular Components
Lets make a better react form
Introduction to angular with a simple but complete project
Routing & Navigating Pages in Angular 2

What's hot (20)

PDF
Angular Advanced Routing
PPT
Spring Boot in Action
PPTX
Angular 14.pptx
PDF
Documenting your REST API with Swagger - JOIN 2014
PDF
Building blocks of Angular
PPTX
Angular Basics.pptx
PDF
Introduction to Node.js
PPTX
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
PDF
Declarative UIs with Jetpack Compose
PPTX
Spring Boot Tutorial
PPTX
Introduction to Django
PDF
CONTINUOUS INTEGRATION WITH JENKINS AND GIT
PPTX
Introduction to github slideshare
PPTX
Angular 2.0 Dependency injection
PDF
Microservices with Java, Spring Boot and Spring Cloud
PPTX
PPT
Spring ppt
PDF
Spring boot jpa
PPTX
[Final] ReactJS presentation
PPTX
Angular introduction students
Angular Advanced Routing
Spring Boot in Action
Angular 14.pptx
Documenting your REST API with Swagger - JOIN 2014
Building blocks of Angular
Angular Basics.pptx
Introduction to Node.js
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Declarative UIs with Jetpack Compose
Spring Boot Tutorial
Introduction to Django
CONTINUOUS INTEGRATION WITH JENKINS AND GIT
Introduction to github slideshare
Angular 2.0 Dependency injection
Microservices with Java, Spring Boot and Spring Cloud
Spring ppt
Spring boot jpa
[Final] ReactJS presentation
Angular introduction students
Ad

Similar to Step by Step Guide on Lazy Loading in Angular 11 (20)

PDF
Implement lazy loading in your existing angular application (get a faster, be...
PPTX
Web worker in your angular application
PDF
Building a dynamic SPA website with Angular
PPTX
What is Angular Ivy?
PPTX
UQ21CA642BA1-Unit-3-WAF-Class18-Introduction to Angular Routing.pptx
PPTX
What’s New in Angular 15.pptx
PDF
What are The Top Features of Angular 7?
PDF
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
PDF
AngularJS Project Setup step-by- step guide - RapidValue Solutions
PDF
Angular version 10 is here check out the new features, notable changes, depr...
PDF
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
PPTX
PDF
E2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
PPTX
AngularJS Fundamentals + WebAPI
PPTX
Lazy angular w/ webpack
PDF
Server-Side Rendering (SSR) with Angular Universal
PDF
AngularJS in practice
PDF
AngularJS A comprehensive beginner s guide to angular js 3nd Edition Rufus St...
PPT
Maven Introduction
PDF
Open sap ui5 - week_2 unit_1_syjewa_exercises
Implement lazy loading in your existing angular application (get a faster, be...
Web worker in your angular application
Building a dynamic SPA website with Angular
What is Angular Ivy?
UQ21CA642BA1-Unit-3-WAF-Class18-Introduction to Angular Routing.pptx
What’s New in Angular 15.pptx
What are The Top Features of Angular 7?
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
AngularJS Project Setup step-by- step guide - RapidValue Solutions
Angular version 10 is here check out the new features, notable changes, depr...
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
E2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
AngularJS Fundamentals + WebAPI
Lazy angular w/ webpack
Server-Side Rendering (SSR) with Angular Universal
AngularJS in practice
AngularJS A comprehensive beginner s guide to angular js 3nd Edition Rufus St...
Maven Introduction
Open sap ui5 - week_2 unit_1_syjewa_exercises
Ad

More from Katy Slemon (20)

PDF
React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
PDF
Data Science Use Cases in Retail & Healthcare Industries.pdf
PDF
How Much Does It Cost To Hire Golang Developer.pdf
PDF
What’s New in Flutter 3.pdf
PDF
Why Use Ruby On Rails.pdf
PDF
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
PDF
How to Implement Middleware Pipeline in VueJS.pdf
PDF
How to Build Laravel Package Using Composer.pdf
PDF
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
PDF
How to Develop Slack Bot Using Golang.pdf
PDF
IoT Based Battery Management System in Electric Vehicles.pdf
PDF
Understanding Flexbox Layout in React Native.pdf
PDF
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
PDF
New Features in iOS 15 and Swift 5.5.pdf
PDF
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
PDF
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
PDF
Flutter Performance Tuning Best Practices From the Pros.pdf
PDF
Angular Universal How to Build Angular SEO Friendly App.pdf
PDF
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
PDF
Ruby On Rails Performance Tuning Guide.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdf
How Much Does It Cost To Hire Golang Developer.pdf
What’s New in Flutter 3.pdf
Why Use Ruby On Rails.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How to Implement Middleware Pipeline in VueJS.pdf
How to Build Laravel Package Using Composer.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
How to Develop Slack Bot Using Golang.pdf
IoT Based Battery Management System in Electric Vehicles.pdf
Understanding Flexbox Layout in React Native.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
New Features in iOS 15 and Swift 5.5.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
Flutter Performance Tuning Best Practices From the Pros.pdf
Angular Universal How to Build Angular SEO Friendly App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
Ruby On Rails Performance Tuning Guide.pdf

Recently uploaded (20)

PDF
Advanced IT Governance
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
Transforming Manufacturing operations through Intelligent Integrations
PDF
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Advanced IT Governance
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
GamePlan Trading System Review: Professional Trader's Honest Take
Transforming Manufacturing operations through Intelligent Integrations
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
Diabetes mellitus diagnosis method based random forest with bat algorithm
madgavkar20181017ppt McKinsey Presentation.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Review of recent advances in non-invasive hemoglobin estimation
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Reach Out and Touch Someone: Haptics and Empathic Computing
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf

Step by Step Guide on Lazy Loading in Angular 11

  • 1. A Complete Tutorial on Lazy Loading in Angular v11 www.bacancytechnology.com
  • 2. Table of Index 1. Introduction 2. What is Lazy Loading in Angular? 3. Why we need Lazy Loading in Angular? 4. Angular lazy loading example: Steps to implement Lazy Loading 5. Watch it being lazily load 6. How to verify Lazy Loading in Angular? 7. Conclusion
  • 4. We have already discussed Angular routing in Angular v11 in the previous blog. In which I have provided a step-by-step guide for Basic Angular Routing and Nested Routing with params with Github repository. Before learning about Lazy Loading in Angular, I would suggest you to go through that for revising the fundamentals. So, let’s be enthusiastic about implementing and learning Angular Lazy Loading!
  • 5. What is Lazy Loading in Angular?
  • 6. In case you have worked with any front-end frameworks, then you might have heard the term Lazy Loading. The idea behind it is similar irrespective of various frameworks. Lazy loading is a technique that permits you to load the javascript components only when their respective routes are active or being hit. It increases the performance and speed of the application by splitting the app into various bundles. As per the user navigation, bundles are being loaded as required.
  • 8. Sometimes we want to load only those routes whose UI is being displayed. For example, if I’m on the Home page right now, I would not prefer to load the Marvel Movies page and DC Movies page. You might not understand the advantage of lazy loading in the website having few pages. Still, this technique will create a more significant difference in performance when the application is quite large. For that purpose, I would rather lazily load the components.
  • 10. Here’s the Github repository where you can find the source code. Create a module and separate routing file named lazy-loading. The purpose of independent routing is to handle all the components associated with angular lazy- loading module. ng g m lazy-loading --routing Create a module and separate routing file
  • 11. Create a component named lazy-demo within the lazy-loading module ng g c lazy-demo We will be adding a link in the header on whose route we will implement lazy loading. app.component.html <li class="nav-item"> <a class="nav-link" [routerLink]="['/lazy- loading']"> Lazy Loading </a> </li> Create a component Adding Link to Header
  • 12. Now, we will lazily load the component, which will be displayed on the route – /lazy- loading Make necessary changes in app- routing.module.ts. Here we will load the module lazily using loadChildren app-routing.module.ts { path: 'lazy-loading', loadChildren: () => import('./lazy- loading/lazy-loading.module') .then(m => m.LazyLoadingModule) }, Lazy Loading with loadChildren
  • 13. It’s time to set up the route in lazy-loading- routing.module.ts. lazy-loading-routing.module.ts Setting up the route
  • 14. import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; import { LazyDemoComponent } from './lazy- demo/lazy-demo.component'; const routes: Routes = [ { path: '', component: LazyDemoComponent } ]; @NgModule({ imports: [RouterModule.forChild(routes)], exports: [RouterModule] }) export class LazyLoadingRoutingModule { }
  • 16. Thus, we have seen the steps for implementing Lazy loading in Angular. After following the instructions, you’ll see something similar to this (excluding CSS and text)- Video URL: https://www.bacancytechnology.com/blog/w p-content/uploads/2021/03/video.mp4?_=1 You will observe that main.js is being served on refreshing the browser. And the Lazy Loading module is loaded only on hitting the route /lazy-loading.
  • 17. How to verify Lazy loading in Angular?
  • 18. The video mentioned above is proof that Lazy loading is working fine. But here are other ways to verify the implemented lazy loading in Angular. Run the following command to generate build- npm run build And you’ll notice something like this –
  • 19. The above image verifies that a separate chunk is generated for the lazy loading module. Another way to verify is to open the dist folder of your project. There you will notice a separate file for the module which uses Lazy Loading. Below is the reference image –
  • 21. So, this was about implementing Lazy loading in Angular from scratch. Many developers choose ngx-loadable for implementing lazy loading in an existing Angular application. If you don’t have an idea regarding it, you can visit this blog- Implement Lazy loading in Angular Web app using ngx-loadable. Despite providing solutions, it is challenging to follow steps when dealing with large-scale applications or decrease production build size by benefiting from Lazy Loading. At such times, it’s beneficial to take help from experts. If you are looking for a helping hand, contact Bacancy Technology and hire Angular developer having experience and expertise in Angular web development. Conclusion