SlideShare a Scribd company logo
What is Lazy Loading?
- Eager Loading
- Lazy Loading
- All angular modules "NgModules" are eagerly loaded.
- Modules are loaded along with application.
- It makes application heavy on browser.
- It makes page rendering slow.
- Even you are not using specific module, it is loaded into memory.
- Lazy Loading is a design pattern
- Lazy loading allows to load NgModules only when they are required.
- It keeps initial bundle size smaller
- It improves render time. It decreases the page load time.
- It is more light weight.
Ex:
1. Create a new Application with Routing Enabled
- Open your workspace
- Create a new Application with routing
> ng generate application Amazon --routing
2. Create Modules for your application
- Open your "app" folder in terminal
- Generate modules with individual route
> ng g module vendors --route vendors --module app.module
> ng g module customers --route customers --module app.module
3. Every module comprises of following files
-customers-routing.module.ts [child routes]
-customers.module.ts [child modules registration]
-customers.component.ts
-customers.component.html
-customers.component.css
- customers-routing.module.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { CategoriesComponent } from './categories.component';
const routes: Routes = [{ path: '', component: CategoriesComponent }];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class CategoriesRoutingModule { }
4. app-routing.module.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
const routes: Routes = [
{ path: 'categories', loadChildren: () => import('./categories/categories.module').then(m =>
m.CategoriesModule)},
{ path: 'vendors', loadChildren: () => import('./vendors/vendors.module').then(m =>
m.VendorsModule) },
{ path: 'products', loadChildren: () => import('./products/products.module').then(m =>
m.ProductsModule) }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
4. Create Navigation from "app.component.html"
<h2>Amazon Portal</h2>
<div>
<button routerLink="">Home</button>
<button routerLink="/categories">Categories</button>
<button routerLink="/vendors">Vendors</button>
<button routerLink="/products">Products</button>
</div>
<div style="margin-top: 30px;">
<router-outlet></router-outlet>
</div>

More Related Content

PPTX
Rise of the responsive single page application
PDF
How to develop browser extension
PPTX
Single page application
PDF
Introduction To Single Page Application
ODP
Joomla Basics
PPTX
Jaggery Introductory Webinar
PPTX
Single Page Application (SPA) using AngularJS
PDF
Single page applications
Rise of the responsive single page application
How to develop browser extension
Single page application
Introduction To Single Page Application
Joomla Basics
Jaggery Introductory Webinar
Single Page Application (SPA) using AngularJS
Single page applications

What's hot (7)

PPTX
Single page application and Framework
PPTX
Work with Composer
PPTX
Web application using JSP
PPTX
Making Single Page Applications (SPA) faster
PDF
Resume Mayuri Zawar
PPTX
Responsive Web Design Automation using Galen
PDF
WordPress development checklist
Single page application and Framework
Work with Composer
Web application using JSP
Making Single Page Applications (SPA) faster
Resume Mayuri Zawar
Responsive Web Design Automation using Galen
WordPress development checklist
Ad

Similar to What is Lazy Loading (11)

PDF
8 things you didn't know about the Angular Router, you won't believe #6!
PDF
Step by Step Guide on Lazy Loading in Angular 11
PDF
Implement lazy loading in your existing angular application (get a faster, be...
PPTX
Angular Lazy Loading and Resolve (Route Resolver)
PDF
Angularjs - lazy loading techniques
PDF
Angular performance slides
PDF
New power of Angular2 Router
PDF
Angular Advanced Routing
PDF
Rethinking Angular Architecture & Performance
PPTX
Angular modules in depth
PDF
Angular Interview Question & Answers PDF By ScholarHat
8 things you didn't know about the Angular Router, you won't believe #6!
Step by Step Guide on Lazy Loading in Angular 11
Implement lazy loading in your existing angular application (get a faster, be...
Angular Lazy Loading and Resolve (Route Resolver)
Angularjs - lazy loading techniques
Angular performance slides
New power of Angular2 Router
Angular Advanced Routing
Rethinking Angular Architecture & Performance
Angular modules in depth
Angular Interview Question & Answers PDF By ScholarHat
Ad

Recently uploaded (20)

PPTX
Supervised vs unsupervised machine learning algorithms
PPT
Chapter 2 METAL FORMINGhhhhhhhjjjjmmmmmmmmm
PPTX
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
PPT
Quality review (1)_presentation of this 21
PPTX
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
PPTX
climate analysis of Dhaka ,Banglades.pptx
PDF
“Getting Started with Data Analytics Using R – Concepts, Tools & Case Studies”
PPTX
Computer network topology notes for revision
PPTX
Database Infoormation System (DBIS).pptx
PPTX
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
PPTX
Business Acumen Training GuidePresentation.pptx
PPTX
Logistic Regression ml machine learning.pptx
PDF
Galatica Smart Energy Infrastructure Startup Pitch Deck
PPTX
IB Computer Science - Internal Assessment.pptx
PPTX
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pptx
PPT
Reliability_Chapter_ presentation 1221.5784
PDF
TRAFFIC-MANAGEMENT-AND-ACCIDENT-INVESTIGATION-WITH-DRIVING-PDF-FILE.pdf
PDF
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
PPTX
STUDY DESIGN details- Lt Col Maksud (21).pptx
PPTX
Introduction-to-Cloud-ComputingFinal.pptx
Supervised vs unsupervised machine learning algorithms
Chapter 2 METAL FORMINGhhhhhhhjjjjmmmmmmmmm
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
Quality review (1)_presentation of this 21
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
climate analysis of Dhaka ,Banglades.pptx
“Getting Started with Data Analytics Using R – Concepts, Tools & Case Studies”
Computer network topology notes for revision
Database Infoormation System (DBIS).pptx
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
Business Acumen Training GuidePresentation.pptx
Logistic Regression ml machine learning.pptx
Galatica Smart Energy Infrastructure Startup Pitch Deck
IB Computer Science - Internal Assessment.pptx
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pptx
Reliability_Chapter_ presentation 1221.5784
TRAFFIC-MANAGEMENT-AND-ACCIDENT-INVESTIGATION-WITH-DRIVING-PDF-FILE.pdf
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
STUDY DESIGN details- Lt Col Maksud (21).pptx
Introduction-to-Cloud-ComputingFinal.pptx

What is Lazy Loading

  • 1. What is Lazy Loading? - Eager Loading - Lazy Loading - All angular modules "NgModules" are eagerly loaded. - Modules are loaded along with application. - It makes application heavy on browser. - It makes page rendering slow. - Even you are not using specific module, it is loaded into memory. - Lazy Loading is a design pattern - Lazy loading allows to load NgModules only when they are required. - It keeps initial bundle size smaller - It improves render time. It decreases the page load time. - It is more light weight. Ex: 1. Create a new Application with Routing Enabled - Open your workspace - Create a new Application with routing > ng generate application Amazon --routing 2. Create Modules for your application - Open your "app" folder in terminal - Generate modules with individual route > ng g module vendors --route vendors --module app.module > ng g module customers --route customers --module app.module 3. Every module comprises of following files -customers-routing.module.ts [child routes] -customers.module.ts [child modules registration] -customers.component.ts -customers.component.html -customers.component.css - customers-routing.module.ts import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; import { CategoriesComponent } from './categories.component'; const routes: Routes = [{ path: '', component: CategoriesComponent }]; @NgModule({ imports: [RouterModule.forChild(routes)], exports: [RouterModule] }) export class CategoriesRoutingModule { } 4. app-routing.module.ts
  • 2. import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; const routes: Routes = [ { path: 'categories', loadChildren: () => import('./categories/categories.module').then(m => m.CategoriesModule)}, { path: 'vendors', loadChildren: () => import('./vendors/vendors.module').then(m => m.VendorsModule) }, { path: 'products', loadChildren: () => import('./products/products.module').then(m => m.ProductsModule) } ]; @NgModule({ imports: [RouterModule.forRoot(routes)], exports: [RouterModule] }) export class AppRoutingModule { } 4. Create Navigation from "app.component.html" <h2>Amazon Portal</h2> <div> <button routerLink="">Home</button> <button routerLink="/categories">Categories</button> <button routerLink="/vendors">Vendors</button> <button routerLink="/products">Products</button> </div> <div style="margin-top: 30px;"> <router-outlet></router-outlet> </div>