Sub topic 16
Checking load cost in the Network panel
This chapter covers the Network panel and the load-time cost of an Angular app. It assumes you can run an Angular CLI build, read a Performance panel recording, and use basic DevTools panels. Earlier chapters covered runtime cost: long tasks, change detection, and templates. Here you measure the cost that comes before any of that, which is downloading the code.
Why load cost belongs in a profiling session
Every kilobyte of JavaScript costs twice. The browser must download it, and then parse, compile, and run it on the main thread. A large initial bundle delays the first render, and it also produces long tasks during bootstrap that you can see in the flame chart. The Network panel shows the download half. The Performance panel shows the execution half. Check both before you decide where to optimize.
Set up a fair measurement
Network numbers from ng serve are misleading. The development server does not minify, does not tree-shake as aggressively, and often does not compress. Measure a production build.
ng build --configuration production
npx http-server dist/my-app/browser -p 8080 --gzipThe output folder depends on your project name and builder. Recent projects write to dist/<name>/browser.
Then prepare DevTools:
- Open the Network panel and tick Disable cache while DevTools is open, so each reload measures a cold load.
- Choose a throttling profile such as Fast 4G or Slow 4G from the throttling dropdown.
- Clear the log, then reload with Ctrl+Shift+R (Cmd+Shift+R on macOS).
- Wait for the
Loadtime in the footer before reading numbers.
Read the request list
Each row is one request. These columns matter most for load cost.
| Column | What it tells you |
|---|---|
| Name | The file, such as `main-ABC123.js` or `chunk-XYZ789.js`. |
| Type | The resource kind, such as `script`, `stylesheet`, or `fetch`. |
| Initiator | What caused the request. A lazy chunk points back to the file that imported it. |
| Size | Two values: bytes transferred over the network, and the uncompressed resource size. |
| Time | Total time for the request. |
| Waterfall | When the request started, waited, and finished relative to others. |
The footer summarizes the whole page: request count, transferred size, resource size, and the DOMContentLoaded and Load times. Record these values. You will compare them after a change.
Right-click the column header to add Content-Encoding or Protocol. If the Size column shows the same number for both values on a JavaScript file, the server probably did not compress it.
Separate transferred size from resource size
Transferred size is what crossed the network, and it is what drives download time. Resource size is the decompressed size, and it is what the browser must parse and execute. A bundle can be 80 kB over the wire and 300 kB to parse. Compare both:
- A big gap between the two means compression is working. Parse cost still follows the larger number.
- No gap on
.jsor.cssfiles means compression is missing. Fix the server configuration before touching code. - A small transferred size with
(disk cache)or(memory cache)means the browser did not use the network at all. That is the reason to disable the cache for cold-load tests.
Find what is in the initial load
Filter the list with the JS button. A typical Angular build produces these files:
main-*.jsholds your application code and the framework code it uses.polyfills-*.jsholds browser compatibility code, and includes Zone.js if your app uses it.styles-*.cssholds global styles.chunk-*.jsholds shared code and lazy-loaded route code.
Sort by Size. Anything large that loads before the first view is a candidate for lazy loading or removal. Use the Initiator column to check that a route chunk loads only on navigation. If you navigate to a lazy route and no new chunk appears, that route is bundled into the initial load.
import { Routes } from '@angular/router';
export const routes: Routes = [
{
path: 'reports',
loadComponent: () =>
import('./reports/reports.component').then(m => m.ReportsComponent),
},
];After this change, reports code should arrive as a separate chunk when the user first opens that route. Confirm it in the Network panel.
Find what is inside a large bundle
The Network panel tells you a file is big, not why. Generate a stats file and inspect it:
ng build --configuration production --stats-jsonWith the esbuild-based application builder, this writes stats.json next to the build output. You can upload it to the esbuild bundle analyzer at esbuild.github.io/analyze to see which packages and files take the space. Common findings are a whole utility library imported for one function, a date or chart library that could be lazy-loaded, and locale data you do not use.
Enforce a size limit with budgets
A budget makes the build warn or fail when a bundle grows past a limit. It catches regressions that nobody notices in manual testing. Add it to the production configuration of the build target in angular.json:
{
"budgets": [
{ "type": "initial", "maximumWarning": "500kB", "maximumError": "1MB" },
{ "type": "anyComponentStyle", "maximumWarning": "2kB", "maximumError": "4kB" }
]
}Budgets measure the build output, not the transferred size. Treat them as a guard, and use the Network panel for the real figure.
A repeatable checking workflow
Edge cases and common errors
- Throttling does not model your server. DevTools throttling limits bandwidth and adds latency in the browser. It does not reproduce a slow backend or a distant CDN.
- Warm loads hide problems. A repeat visit with hashed filenames and long
Cache-Controllifetimes may download almost nothing. Test cold loads for first-visit cost and warm loads for returning users, and label which one you recorded. - Service workers change the picture. If the app registers a service worker, rows may say
(ServiceWorker). Tick Bypass for network in the Application panel when you need raw network numbers. - Extensions add requests. Profile in an Incognito window with extensions disabled so injected scripts do not appear in your totals.
- HTTP/2 changes the tradeoff. With multiplexing, many small chunks are cheap to request, so a long waterfall is not automatically a problem. Look at when the first render happens, not only at request count.
- Network size is not render time. A small bundle can still block the main thread for a long time. Always pair this panel with a Performance recording of the same load.
Exercise
Exercise
You reload a production Angular app with the cache disabled. main-*.js shows 410 kB transferred and 410 kB resource size. Name the likely cause, and give one way to check it in the Network panel.
Show answer
The server is probably not compressing the file, because transferred and resource sizes are equal. Add the Content-Encoding column, or open the request's Headers tab, and look for gzip, br, or zstd. If it is missing, enable compression on the server or CDN, then reload and compare the two sizes again.
Exercise
After navigating to a lazy reports route, no new JavaScript request appears in the Network panel. What does that suggest, and what would you check next?
Show answer
The route code is probably part of the initial bundle, so the lazy loading is not taking effect. Check that the route uses loadComponent or loadChildren with a dynamic import(), and that no other file imports the component statically. Then rebuild and confirm a separate chunk appears when you open the route.