Professional Documents
Culture Documents
Route Preloading Strategies in Angular
Route Preloading Strategies in Angular
dev/route-preloading-in-angular/
SHARE
1 of 12 30/01/23, 15:26
Route preloading strategies in Angular https://web.dev/route-preloading-in-angular/
Minko Gechev
Twitter GitHub Glitch Homepage
On this page
Route-level code splitting can help you reduce the initial load time of an application by
delaying the JavaScript associated with routes that aren't initially needed. This way, the
Angular router waits until a user navigates to a given route before triggering a network
request to download the associated JavaScript.
While this technique is great for initial page load, it can slow down navigation,
depending on the users' network latency and bandwidth. One way to tackle this
problem is route preloading. Using preloading, when the user is at a given route, you SHARE
SUBSCRIBE
2 of 12 30/01/23, 15:26
Route preloading strategies in Angular https://web.dev/route-preloading-in-angular/
QuicklinkStrategy , which preloads only the routes associated with links on the
current page.
The rest of this post refers to a sample Angular app. You can find the source code on
GitHub.
SHARE
SUBSCRIBE
3 of 12 30/01/23, 15:26
Route preloading strategies in Angular https://web.dev/route-preloading-in-angular/
// …
Now serve the application and look at the Network panel in Chrome DevTools:
You should see that the router downloaded nyan-nyan-module.js and about-
about-module.js in the background when you opened the application:
SHARE
SUBSCRIBE
4 of 12 30/01/23, 15:26
Route preloading strategies in Angular https://web.dev/route-preloading-in-angular/
0:00 / 0:07
The router also registered the modules' route declarations so that when you navigate
to a URL associated with any of the preloaded modules, the transition is instantaneous.
SHARE
SUBSCRIBE
5 of 12 30/01/23, 15:26
Route preloading strategies in Angular https://web.dev/route-preloading-in-angular/
@NgModule({
SHARE
SUBSCRIBE
6 of 12 30/01/23, 15:26
Route preloading strategies in Angular https://web.dev/route-preloading-in-angular/
SHARE
SUBSCRIBE
7 of 12 30/01/23, 15:26
Route preloading strategies in Angular https://web.dev/route-preloading-in-angular/
SHARE
SUBSCRIBE
8 of 12 30/01/23, 15:26
Route preloading strategies in Angular https://web.dev/route-preloading-in-angular/
SHARE
SUBSCRIBE
9 of 12 30/01/23, 15:26
Route preloading strategies in Angular https://web.dev/route-preloading-in-angular/
SHARE
SUBSCRIBE
10 of 12 30/01/23, 15:26
Route preloading strategies in Angular https://web.dev/route-preloading-in-angular/
SHARE
SUBSCRIBE
11 of 12 30/01/23, 15:26
Route preloading strategies in Angular https://web.dev/route-preloading-in-angular/
SHARE
SUBSCRIBE
12 of 12 30/01/23, 15:26