Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Improving Start-up Performance with Lazy Loadin...
Search
Manfred Steyer
PRO
December 09, 2016
Programming
550
0
Share
Improving Start-up Performance with Lazy Loading in Angular 2
Slides from talk at ngbe in Belgium, 2016
Manfred Steyer
PRO
December 09, 2016
More Decks by Manfred Steyer
See All by Manfred Steyer
Agentic UI with Angular @ngAir April 2025
manfredsteyer
PRO
0
18
Migration to Signals, Signal Forms, Resource API, and NgRx Signal Store @Angular Days 03/2026 Munich
manfredsteyer
PRO
0
250
AI Assistants for YourAngular Solutions @Angular Graz, March 2026
manfredsteyer
PRO
0
170
AI Assistants for Your Angular Solutions @ngVienna March 2026
manfredsteyer
PRO
0
86
AI Assistants for Your Angular Solutions
manfredsteyer
PRO
0
180
Nostalgia Meets Technology: Super Mario with TypeScript
manfredsteyer
PRO
0
130
Full Cycle Reactivity in Angular: SignalStore mit Signal Forms und Resources
manfredsteyer
PRO
0
99
Premier Disciplin for Micro Frontends Multi Version/ Framework Scenarios @OOP 2026, Munic
manfredsteyer
PRO
0
260
Beyond the Basics: Signal Forms
manfredsteyer
PRO
0
170
Other Decks in Programming
See All in Programming
「速くなった気がする」をデータで疑う
senleaf24
0
150
感情を設計する
ichimichi
5
1.3k
Nuxt Server Components
wattanx
0
260
Laravel Nightwatchの裏側 - Laravel公式Observabilityツールを支える設計と実装
avosalmon
1
330
実践CRDT
tamadeveloper
0
410
今こそ押さえておきたい アマゾンウェブサービス(AWS)の データベースの基礎 おもクラ #6版
satoshi256kbyte
1
230
PHP で mp3 プレイヤーを実装しよう
m3m0r7
PRO
0
210
PHPで TLSのプロトコルを実装してみる
higaki_program
0
750
Radical Imagining - LIFT 2025-2027 Policy Agenda
lift1998
0
250
車輪の再発明をしよう!PHP で実装して学ぶ、Web サーバーの仕組みと HTTP の正体
h1r0
3
510
iOS機能開発のAI環境と起きた変化
ryunakayama
0
170
年間50登壇、単著出版、雑誌寄稿、Podcast出演、YouTube、CM、カンファレンス主催……全部やってみたので面白さ等を比較してみよう / I’ve tried them all, so let’s compare how interesting they are.
nrslib
4
750
Featured
See All Featured
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
160
エンジニアに許された特別な時間の終わり
watany
106
240k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.7k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
250
Tell your own story through comics
letsgokoyo
1
890
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
210
Art, The Web, and Tiny UX
lynnandtonic
304
21k
Visualization
eitanlees
150
17k
Being A Developer After 40
akosma
91
590k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
460
A Tale of Four Properties
chriscoyier
163
24k
Transcript
Improving Start-up Performance with Lazy Loading in Angular 2 Manfred
Steyer SOFTWAREarchitekt.at ManfredSteyer
About me … • Manfred Steyer • SOFTWAREarchitekt.at • Trainer
& Consultant • Focus: Angular • Google Developer Expert (GDE) Page 2 Manfred Steyer
Contents • Lazy Loading • Prevent Lazy Loading • Preloading
• Shared Modules and Lazy Loading Page 3
Lazy Loading Page 4
Module Structure Page 5 AppModule … … … SharedModule
Root Module Feature Modules Shared Module
Lazy Loading Page 6 AppModule … … … SharedModule
Root Module Feature Modules Shared Module
Root Module with Lazy Loading Page 7 const APP_ROUTE_CONFIG:
Routes = [ { path: 'home', component: HomeComponent }, { path: 'flights', loadChildren: './[…]flight-booking.module#FlightBookingModule' } ];
Routes for Feature Module Page 8 const FLIGHT_ROUTES =
[ { path: '/bookings', component: FlightBookingComponent, […] }, […] } Url: /flights/bookings Triggers Lazy Loading
webpack configuration • angular2-router-loader • splits bundle into several chunks
Page 9
DEMO Page 10
Prevent Lazy-Loading
Guards • Services that can intercept routing • Can prevent
requested action
Base Types for Guards CanActivate CanActivateChild CanDeactivate CanLoad
Sample @Injectable() export class AuthLoadGuard implements CanLoad { canLoad(route: Route):
Observale<boolean> | Promise<boolean> | boolean { return true; } }
Configure a Guard let APP_ROUTES: Routes = [ { path:
'flight-booking', loadChildren: ‚[…]', canLoad: [AuthLoadGuard] }, […] } Just a Token // Your Module providers: [ { provide: AuthLoadGuard, useClass: AuthLoadGuard} ],
Caution • This has nothing to do with security •
It’s about usability
DEMO
Preloading Page 18
Idea • Modules that might be needed later are loaded
after (!) the start of the application • When the module is actually needed later, it is available immediately Page 19
Activating Preloading Page 20 const AppRoutesModule = RouterModule.forRoot( ROUTE_CONFIG,
{ preloadingStrategy: PreloadAllModules });
DEMO Page 21
Lazy Loading and Shared Modules Page 22
DEMO Page 23
Lazy Loading and Shared Modules Page 24 AppModule FlightModule
SharedModule includes includes (lazy) includes AuthService
Lazy Loading and Shared Modules Page 25 AppModule FlightModule
SharedModule includes includes (lazy) includes AuthService AuthService
Lazy Loading and Shared Modules Page 26 AppModule FlightModule
SharedModule includes includes (lazy) includes AuthService AuthService
Solution Page 27 AppModule FlightModule SharedModule includes (with Providers)
includes (lazy) includes (without Providers) AuthService
Shared Module Page 28 @NgModule({ […], providers: [] })
export class SharedModule { }
Shared Module Page 29 @NgModule({ […], providers: [] })
export class SharedModule { static forRoot(): ModuleWithProviders { return { ngModule: SharedModule, providers: [AuthService, […]] } } }
DEMO Page 30
Summary Page 31 Lazy Loading of Modules webpack splits
bundle Prevent Lazy Loading with Guards Preloading Strategy Shared Modules w/ and w/o Providers Lots of lazy animals on the web ;-)
Contact [mail]
[email protected]
[blog] SOFTWAREarchitekt.at [twitter] ManfredSteyer