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
Angular, Lazy Loading, ngVikings in Copenhagen,...
Search
Manfred Steyer
PRO
February 11, 2017
Programming
1
500
Angular, Lazy Loading, ngVikings in Copenhagen, Feb 2017
Manfred Steyer
PRO
February 11, 2017
Tweet
Share
More Decks by Manfred Steyer
See All by Manfred Steyer
Successful with Signals: 3 Patterns for Your Architecture
manfredsteyer
PRO
0
48
Native Federation: The Future of Micro Frontends in Angular
manfredsteyer
PRO
0
290
Architectures with Lightweight Stores: New Rules and Options
manfredsteyer
PRO
0
220
3 Effective Rules for Success with Signals in Angular
manfredsteyer
PRO
1
250
Modern Angular: Renovation for Your Applications
manfredsteyer
PRO
0
200
Where do we go from here? Strategies for Signals
manfredsteyer
PRO
0
200
Successful with Signals: 3 Effective Rules
manfredsteyer
PRO
0
110
Vertical Architectures for Scalable Angular Applications
manfredsteyer
PRO
0
340
Successful with Signals: 3 Effective Rules
manfredsteyer
PRO
0
120
Other Decks in Programming
See All in Programming
Swift Concurrencyとレースコンディション
objectiveaudio
1
390
メモリ最適化を究める!iOSアプリ開発における5つの重要なポイント
yhirakawa333
0
380
フロントエンドカンファレンス北海道2024 『小規模サイトでも使えるVite 〜HTMLコーディングをよりスマートに〜』長谷川広武(ハム)
h2ham
1
2.5k
Ruby Parser progress report 2024
yui_knk
2
190
Method Swizzlingを行うライブラリにおけるマルチモジュール設計
yoshikma
0
110
オートマトン学習しろ / Do automata learning
makenowjust
3
110
Boost Your Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
1
1.1k
Playwrightから始めるVisual Regression Testingのススメ by とっと
totto2727
2
1.8k
Why Prism?
kddnewton
4
1.3k
仮想ファイルシステムを導入して開発環境のストレージ課題を解消する
segadevtech
2
430
全力の跳躍を捉える計測アプリを作る
ogijun2018
1
1.2k
Web技術を駆使してユーザーの画面を「録画」する
yukukotani
13
6.4k
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
135
6.5k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
29
2.6k
What's in a price? How to price your products and services
michaelherold
242
11k
BBQ
matthewcrist
83
9.1k
Fantastic passwords and where to find them - at NoRuKo
philnash
47
2.8k
How GitHub Uses GitHub to Build GitHub
holman
472
290k
ParisWeb 2013: Learning to Love: Crash Course in Emotional UX Design
dotmariusz
109
6.9k
How to name files
jennybc
75
98k
Visualization
eitanlees
142
15k
Bash Introduction
62gerente
608
210k
In The Pink: A Labor of Love
frogandcode
139
22k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.4k
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 • Preloading • Prevent Lazy Loading
• 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 • creates several chunks Page
9
DEMO Page 10
Preloading Page 11
Idea • Modules that might be needed later are loaded
after (!) the start of the application • When the module is actually needed, it is available immediately Page 12
Activating Preloading Page 13 const AppRoutesModule = RouterModule.forRoot( ROUTE_CONFIG,
{ preloadingStrategy: PreloadAllModules });
DEMO Page 14
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 (lazy) includes
CoreModule includes includes Only import CoreModule into AppModule! Global Providers like AuthService & Shell
DEMO
Huge CoreModule? Page 29 AppModule FlightModule SharedModule includes (lazy)
includes CoreModule includes includes
Solution (for Libraries) Page 30 AppModule FlightModule AuthModule includes
(lazy) CoreModule
Solution (for Libraries) Page 31 AppModule FlightModule AuthModule includes
(lazy) includes (with Services) CoreModule includes includes (without Services)
Auth Module Page 32 @NgModule({ […], providers: [] })
export class AuthModule { }
Auth Module Page 33 @NgModule({ […], providers: [] })
export class AuthModule { static forRoot(): ModuleWithProviders { return { ngModule: AuthModule, providers: [AuthService, […]] } } }
DEMO Page 34
Summary Page 35 Lazy Loading of Modules webpack splits
chunks Prevent Lazy Loading with Guards Preloading Strategy Use Core Module for global Services Shared Modules w/ and w/o Providers
Contact [mail]
[email protected]
[blog] SOFTWAREarchitekt.at [twitter] ManfredSteyer