Sub topic 16
Checking load cost in the Network panel
This chapter assumes you can run an Angular app with the Angular CLI, open Chrome DevTools, and read a basic Performance trace. Runtime profiling shows how the app behaves after it loads. The Network panel shows what the browser had to download before the app could start.
Why load cost matters
Angular ships JavaScript that the browser must download, parse, and run before the first view appears. A large bundle delays that first view even when your components are fast. Load cost and runtime cost are separate problems, and each needs its own measurement.
Use a production build for this check. A development build is larger and unminified, so its numbers do not reflect what users get.
ng build --configuration productionServe the dist output with a static server and open that address in Chrome.
Recording a load
- Open DevTools and select the Network panel.
- Tick Disable cache so every run starts cold. Leave DevTools open while you reload.
- Choose a throttling profile such as Fast 4G from the throttling menu, as you did for the Performance panel.
- Reload the page and wait for it to settle.
The bottom bar shows the request count, the transferred size, and the resource size. Transferred size is what crossed the network, usually compressed. Resource size is the uncompressed content the browser must parse.
Reading the request list
Filter by JS to see only scripts. Then sort by Size or look at the Waterfall column.
| Column | What it tells you |
|---|---|
| Size | Transferred size, with the uncompressed size below it |
| Time | Total time for that request |
| Waterfall | When each request started, waited, and downloaded |
| Initiator | The file or code that triggered the request |
In a default Angular build, expect files such as main-*.js, polyfills-*.js, and chunk-*.js. If main is far larger than the others, too much code loads up front.
Lazy-loaded chunks
Lazy loading splits routes into separate files that download only when the user visits them. In the Network panel, navigate to a lazy route and watch for a new chunk-*.js request. If nothing appears, that route is part of the initial bundle.
import { Routes } from '@angular/router';
export const routes: Routes = [
{
path: 'reports',
loadComponent: () =>
import('./reports/reports.component').then(m => m.ReportsComponent),
},
];Common errors
- Measuring a development build and concluding the app is huge.
- Leaving the cache enabled, so the second load looks fast.
- Comparing runs with different throttling settings.
- Reading only transferred size and ignoring parse cost. A compressed 200 KB file can still be a large script to execute.
Verifying a change
After you move code to a lazy route or remove a dependency, repeat the same steps with the same throttling profile. Compare the transferred size of the initial JavaScript and the Load time shown at the bottom of the panel. Run it a few times, because one load can vary.
Exercise
You open the Network panel on a development build with the cache enabled and see a 4 MB main.js that loads in 200 ms on your second reload. Name two problems with this measurement and how to fix each.
Show answer
A development build is unminified and larger than production, so build with ng build --configuration production and measure that. The cached reload skips the download, so tick Disable cache, and apply a throttling profile such as Fast 4G to get a realistic time.