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
Using GitHub Actions to Deploy your Workloads to Azure
Kasun Kodagoda
 
PDF
DevOps with GitHub Actions
Nilesh Gule
 
PPTX
CI/CD Overview
An Nguyen
 
PDF
Introduction to GitHub Actions
Bo-Yi Wu
 
PPTX
Transforming Organizations with CI/CD
Cprime
 
PPTX
Fundamentals of DevOps and CI/CD
Batyr Nuryyev
 
PDF
Introduction to GitHub Actions
Knoldus Inc.
 
PDF
CI/CD with Github Actions
Md. Minhazul Haque
 
Using GitHub Actions to Deploy your Workloads to Azure
Kasun Kodagoda
 
DevOps with GitHub Actions
Nilesh Gule
 
CI/CD Overview
An Nguyen
 
Introduction to GitHub Actions
Bo-Yi Wu
 
Transforming Organizations with CI/CD
Cprime
 
Fundamentals of DevOps and CI/CD
Batyr Nuryyev
 
Introduction to GitHub Actions
Knoldus Inc.
 
CI/CD with Github Actions
Md. Minhazul Haque
 

What's hot (20)

PPTX
CICD Pipeline Using Github Actions
Kumar Shìvam
 
PPTX
Git
Shinu Suresh
 
PDF
Git and git flow
Fran García
 
PPTX
Bitrise: Make iOS Builds Faster - Tokyo 2019 March - Cookpad meetup
Viktor Benei
 
PPTX
Mendix Platform
SAKTHIVEL PERIYASAMY
 
PDF
Low code development platform
madisonsmith415303
 
PDF
Gitlab ci-cd
Dan MAGIER
 
PPTX
DevOps and Build Automation
Heiswayi Nrird
 
PDF
Intro to Github Actions @likecoin
William Chong
 
PPTX
GitLab for CI/CD process
HYS Enterprise
 
PPTX
「DevOps with GitLab」でDevOps環境をセットアップしてみた!
VirtualTech Japan Inc./Begi.net Inc.
 
PPTX
Jenkins CI
Viyaan Jhiingade
 
PPTX
Introducing DevOps, IT Sharing Session 20 Nov 2017
Danny Ariwicaksono
 
PDF
What is DevOps | DevOps Introduction | DevOps Training | DevOps Tutorial | Ed...
Edureka!
 
PPTX
Mapping out your API Strategy - 4.20.11 Webinar slides
Apigee | Google Cloud
 
PDF
Shifting Security Left - The Innovation of DevSecOps - ValleyTechCon
Tom Stiehm
 
PPTX
Introduction to DevOps
Matthew David
 
PDF
Cloud FoundryでDockerも.NETも。新しいDiegoの仕組み入門
Kazuto Kusama
 
PPTX
Introduction to GitHub, Open Source and Tech Article
PRIYATHAMDARISI
 
PDF
Introduction to GitHub
Nishan Bose
 
CICD Pipeline Using Github Actions
Kumar Shìvam
 
Git and git flow
Fran García
 
Bitrise: Make iOS Builds Faster - Tokyo 2019 March - Cookpad meetup
Viktor Benei
 
Mendix Platform
SAKTHIVEL PERIYASAMY
 
Low code development platform
madisonsmith415303
 
Gitlab ci-cd
Dan MAGIER
 
DevOps and Build Automation
Heiswayi Nrird
 
Intro to Github Actions @likecoin
William Chong
 
GitLab for CI/CD process
HYS Enterprise
 
「DevOps with GitLab」でDevOps環境をセットアップしてみた!
VirtualTech Japan Inc./Begi.net Inc.
 
Jenkins CI
Viyaan Jhiingade
 
Introducing DevOps, IT Sharing Session 20 Nov 2017
Danny Ariwicaksono
 
What is DevOps | DevOps Introduction | DevOps Training | DevOps Tutorial | Ed...
Edureka!
 
Mapping out your API Strategy - 4.20.11 Webinar slides
Apigee | Google Cloud
 
Shifting Security Left - The Innovation of DevSecOps - ValleyTechCon
Tom Stiehm
 
Introduction to DevOps
Matthew David
 
Cloud FoundryでDockerも.NETも。新しいDiegoの仕組み入門
Kazuto Kusama
 
Introduction to GitHub, Open Source and Tech Article
PRIYATHAMDARISI
 
Introduction to GitHub
Nishan Bose
 
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...
Katy Slemon
 
PPTX
Web worker in your angular application
Suresh Patidar
 
PDF
Building a dynamic SPA website with Angular
Filip Bruun Bech-Larsen
 
PPTX
What is Angular Ivy?
Albiorix Technology
 
PPTX
UQ21CA642BA1-Unit-3-WAF-Class18-Introduction to Angular Routing.pptx
TamalDey28
 
PPTX
What’s New in Angular 15.pptx
Albiorix Technology
 
PDF
What are The Top Features of Angular 7?
NCode Technologies, Inc.
 
PDF
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
Paul Jensen
 
PDF
AngularJS Project Setup step-by- step guide - RapidValue Solutions
RapidValue
 
PDF
Angular version 10 is here check out the new features, notable changes, depr...
Katy Slemon
 
PDF
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
Katy Slemon
 
PPTX
Angular
TejinderMakkar
 
PDF
E2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
Paul Jensen
 
PPTX
AngularJS Fundamentals + WebAPI
Eric Wise
 
PPTX
Lazy angular w/ webpack
Rich Snapp
 
PDF
Server-Side Rendering (SSR) with Angular Universal
Katy Slemon
 
PDF
AngularJS in practice
Eugene Fidelin
 
PDF
AngularJS A comprehensive beginner s guide to angular js 3nd Edition Rufus St...
vivaanpulcha
 
PPT
Maven Introduction
Sandeep Chawla
 
PDF
Open sap ui5 - week_2 unit_1_syjewa_exercises
Borusan Birlik Danışmanlık
 
Implement lazy loading in your existing angular application (get a faster, be...
Katy Slemon
 
Web worker in your angular application
Suresh Patidar
 
Building a dynamic SPA website with Angular
Filip Bruun Bech-Larsen
 
What is Angular Ivy?
Albiorix Technology
 
UQ21CA642BA1-Unit-3-WAF-Class18-Introduction to Angular Routing.pptx
TamalDey28
 
What’s New in Angular 15.pptx
Albiorix Technology
 
What are The Top Features of Angular 7?
NCode Technologies, Inc.
 
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
Paul Jensen
 
AngularJS Project Setup step-by- step guide - RapidValue Solutions
RapidValue
 
Angular version 10 is here check out the new features, notable changes, depr...
Katy Slemon
 
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
Katy Slemon
 
E2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
Paul Jensen
 
AngularJS Fundamentals + WebAPI
Eric Wise
 
Lazy angular w/ webpack
Rich Snapp
 
Server-Side Rendering (SSR) with Angular Universal
Katy Slemon
 
AngularJS in practice
Eugene Fidelin
 
AngularJS A comprehensive beginner s guide to angular js 3nd Edition Rufus St...
vivaanpulcha
 
Maven Introduction
Sandeep Chawla
 
Open sap ui5 - week_2 unit_1_syjewa_exercises
Borusan Birlik Danışmanlık
 
Ad

More from Katy Slemon (20)

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

Recently uploaded (20)

PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PDF
Beyond Automation: The Role of IoT Sensor Integration in Next-Gen Industries
Rejig Digital
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
Architecture of the Future (09152021)
EdwardMeyman
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PPT
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
Doc9.....................................
SofiaCollazos
 
PPTX
Coupa-Overview _Assumptions presentation
annapureddyn
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
Beyond Automation: The Role of IoT Sensor Integration in Next-Gen Industries
Rejig Digital
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Architecture of the Future (09152021)
EdwardMeyman
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Doc9.....................................
SofiaCollazos
 
Coupa-Overview _Assumptions presentation
annapureddyn
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 

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