Skip to main content

03 - How many JavaScript files does an Angular SSR page download: counting them with Resource Timing

An article page requests 69 JavaScript files for 801 KB, the home page 51 for 638 KB. The HTML declares 3: the rest is requested by the running code.

What do you think about this article?

03 - How many JavaScript files does an Angular SSR page download: counting them with Resource Timing
Angular Performancefedericocalo.dev

At a Glance

An article page requests 69 JavaScript files for 801 KB, the home page 51 for 638 KB. The HTML declares 3: the rest is requested by the running code.

In short. A well-built Angular page does not download a single main.js: it downloads a main file and many lazily loaded chunks. The useful question is not "how much does the bundle weigh", it is how many files and how many kilobytes really arrive when you open that page, and this is counted in a minute with the browser's Resource Timing API. On this site, on 8 November 2026, with an emulated phone and an unthrottled network, the home page requests 51 site-owned JavaScript files for 638 KB transferred, the /servizi page 56 files for 681 KB and an article page 69 files for 801 KB. The HTML document of an article declares only 3 script tags and 20 modulepreload hints: the other files are requested by the code while it runs.

The numbers tell you how much code the page pulls down, not how much it costs to run, and they do not explain why it is 69 and not 30. This part gives you the script, shows what it sees and what it cannot see - including a detail of the specification by which the total you read is inflated by a constant - and says clearly what remains to be measured with a build I did not run here.

Method. Playwright 1.59.1 headless Chromium (build chromium_headless_shell-1234), Node.js 24.11.0, Pixel 7 profile, no network or CPU throttling, production of federicocalo.dev on 8 November 2026. The project uses @angular/core 21.2.14 (verified with node -p "require('@angular/core/package.json').version"). Every count and every weight reported here repeated identically in two runs an hour apart; the timings, as you will see, did not.

This is the third part of a series in which I measure this site before touching it: in the first part (in Italian) I measured timings and discovered how much they vary, in the second (in Italian) a width that does not vary at all. Here we count files and bytes, which sit in the middle: stable within the same version of the site, different at every publication.

What "heavy" means

A page can be heavy in three different ways, and confusing them leads to optimising the wrong thing. It can require many requests, each with its own latency. It can transfer many bytes over the wire, already compressed.

It can impose a lot of processor work to parse and run the code once downloaded. The Resource Timing API answers the first two; the third requires a main-thread profile, which I did not take here.

The transferSize field of each entry holds the transferred size, and here the specification must be read instead of guessing: it is not "the body plus the real headers". The W3C specification prescribes three cases - zero if the resource came from the local cache, exactly 300 if it was revalidated, otherwise the compressed size of the body plus 300 - and explains why: that constant stands in for the real weight of the headers, which exposing would reveal the presence of certain cookies.

Translated into a consequence for my numbers: the total of 801 KB on an article page contains that constant 69 times, that is about 20 KB, 2.5% of the total, which is not code. It is little, and yet it is exactly the kind of detail for which a number taken from an API must be read in the API's specification: whoever counts a few large files errs little, whoever counts many small files errs a lot.

A limit to know right away, from the MDN documentation of PerformanceResourceTiming.transferSize: for resources of another origin, the value is zero if the server does not send the Timing-Allow-Origin header with the requesting origin.

For this site it means the third-party scripts, Tag Manager, Analytics and Clarity, appear in the list with zero bytes, and that my total covers only the scripts served by the site itself. The real cost of the page is higher than what I write.

The script

The script opens each path once, waits three seconds after the load event, then from the page reads all resource entries whose path ends in .js, splits them into same-origin ones and the others, and counts how many files exceed 50 KB. The 50 KB threshold is a choice of convenience of mine to bring out the big pieces, not a value recommended by anyone.


import { chromium, devices } from 'playwright';

const [origine, ...percorsi] = process.argv.slice(2);
const browser = await chromium.launch({ executablePath: process.env.CHROME_PATH });

for (const percorso of percorsi) {
  const page = await (await browser.newContext({ ...devices['Pixel 7'] })).newPage();
  await page.goto(origine + percorso, { waitUntil: 'load' });
  await page.waitForTimeout(3000);
  const r = await page.evaluate((origine) => {
    const js = performance.getEntriesByType('resource').filter((e) => new URL(e.name).pathname.endsWith('.js'));
    const mia = js.filter((e) => e.name.startsWith(origine));
    const altri = js.filter((e) => !e.name.startsWith(origine));
    const kb = (v) => Math.round(v.reduce((s, e) => s + e.transferSize, 0) / 1024);
    return {
      mioN: mia.length, mioKB: kb(mia),
      altriN: altri.length, altriKB: kb(altri),
      sopra50: mia.filter((e) => e.transferSize > 50 * 1024).length,
    };
  }, origine);
  console.log(percorso, JSON.stringify(r));
}
await browser.close();

The command takes the origin and then the paths, one per argument. I chose four with a criterion: the home page, a static content page like /servizi, and two different articles instead of one, because two articles are the minimum to tell the cost of the route from the cost of the text it contains.


CHROME_PATH=$HOME/.cache/ms-playwright/chromium_headless_shell-1234/chrome-headless-shell-linux64/chrome-headless-shell \
node peso-js.mjs https://federicocalo.dev /it/ /it/servizi \
  /it/blog/angular-21-ssr-performance-ttfb-core-web-vitals-2026 \
  /it/blog/workflow-professionale-progetto-angular-cursor

The output, one line per path: mioN and mioKB are files and kilobytes served by this domain, altriN and altriKB those of third parties, sopra50 the number of files over 50 KB.


/it/ {"mioN":51,"mioKB":638,"altriN":1,"altriKB":0,"sopra50":4}
/it/servizi {"mioN":56,"mioKB":681,"altriN":1,"altriKB":0,"sopra50":4}
/it/blog/angular-21-ssr-performance-ttfb-core-web-vitals-2026 {"mioN":69,"mioKB":801,"altriN":1,"altriKB":0,"sopra50":5}
/it/blog/workflow-professionale-progetto-angular-cursor {"mioN":69,"mioKB":801,"altriN":1,"altriKB":0,"sopra50":5}

Three things read right away. The first: two different articles have exactly the same numbers, 69 files and 801 KB, which suggests the cost belongs to the shape of the page (the route, the components) and not to the text of the article. It is an inference from two samples, not a proof.

The second: the home page weighs less than a detail page, and the step from 51 to 69 files is not explained by the amount of text. The third: the third-party entries are just one, with zero bytes, and this is the effect of Timing-Allow-Origin described above; it does not mean Tag Manager loads nothing.

What the HTML declares and what the browser requests

The page document is the starting point of everything that arrives afterwards, and it can be read without a browser. I downloaded the HTML of an article page and counted the tags:


curl -s --compressed https://federicocalo.dev/it/blog/workflow-professionale-progetto-angular-cursor -o pagina.html
grep -o 'rel="modulepreload"' pagina.html | wc -l
grep -o '<script[^>]*src=[^>]*>' pagina.html | wc -l

20
3

Twenty modulepreload hints and three script tags with src. The browser reaches 69 JavaScript files: the others are requested by the code while it runs, presumably with dynamic import(), which is the mechanism behind a route component defined with loadComponent (I did not verify it by opening the files).

The project is no exception: in the route files under frontend/src/app there are 737 occurrences of loadComponent, counted with grep -ro "loadComponent" src/app --include=*routes*.ts | wc -l.

Many routes, then, are loaded on demand. I did not, however, open the 69 files one by one to say which route or component each belongs to: without a build and its statistics file, the chunk names (chunk-FGG2EIKH.js and the like) are hashes that do not point back to the source code.

The big chunks, and a detail about time

The pieces above 50 KB are 4 on the home page and 5 on the articles. To see them one by one you just change the body of the script: instead of totals, the list sorted by weight, with the file name and the moment the request started.


const r = await page.evaluate((o) => performance.getEntriesByType('resource')
  .filter((e) => new URL(e.name).pathname.endsWith('.js') && e.name.startsWith(o))
  .map((e) => ({ f: e.name.split('/').pop(), kb: Math.round(e.transferSize / 1024), start: Math.round(e.startTime) }))
  .sort((a, b) => b.kb - a.kb).slice(0, 6), origine);

/it/
   176 KB  start   568 ms  chunk-FGG2EIKH.js
    87 KB  start   568 ms  chunk-TTPLJXEB.js
    81 KB  start   569 ms  chunk-MATBZCZT.js
    61 KB  start   388 ms  main-JWNIMX6J.js
    33 KB  start   387 ms  chunk-IW5ICXUF.js
    27 KB  start   566 ms  chunk-WGHKVMTA.js
/it/blog/angular-21-ssr-performance-ttfb-core-web-vitals-2026
   176 KB  start  1776 ms  chunk-FGG2EIKH.js
    87 KB  start  1776 ms  chunk-TTPLJXEB.js
    81 KB  start  1776 ms  chunk-MATBZCZT.js
    63 KB  start  2259 ms  chunk-6ON7HASR.js
    61 KB  start  1593 ms  main-JWNIMX6J.js
    41 KB  start  1593 ms  chunk-F744HDVC.js

The first three lines are identical on the two pages, names included: chunk-FGG2EIKH, chunk-TTPLJXEB and chunk-MATBZCZT amount to 344 KB of shared code that every page pays, whatever you are reading. The difference between the home page and the article is not there: it lies in the 63 KB chunk-6ON7HASR, which does not appear on the home page.

The time column says something else: the main file starts before the three big chunks (388 against 568 ms on the home page, 1593 against 1776 ms on the article), and among these six files the article-specific one starts last, at 2259 ms. The chain is sequential: the document requests the main file, the main file requests the shared chunks, and the last arrives when the previous ones are already in flight.

On the milliseconds, though, I build no conclusion, and I can show you why. I reran the same script an hour later, on the same production, and this is the time column of the article page in the two rounds, next to the weight column:


file                   KB    start 1a tornata   start 2a tornata
chunk-FGG2EIKH.js     176       1776 ms            5038 ms
chunk-TTPLJXEB.js      87       1776 ms            5038 ms
chunk-MATBZCZT.js      81       1776 ms            5038 ms
chunk-6ON7HASR.js      63       2259 ms            5424 ms
main-JWNIMX6J.js       61       1593 ms            4933 ms
chunk-F744HDVC.js      41       1593 ms            4933 ms

Identical names, identical kilobytes to the rounded byte, identical order - and timings almost tripled: 5038 ms against 1776 for the same chunk. I changed nothing between the two runs. It is the same lesson as in the first part, seen through another API: in this table two columns out of three are facts and one is an anecdote. Weight and number of files you can cite; the milliseconds of a single run you cannot, and when you see them in an article without a range beside them you know someone measured only once.

Where to intervene, and where I chose not to

The Angular documentation on the @defer block (current page as of 2026-11-08, the project is on 21.2.14) gives two conditions for a block's dependencies to be really deferred: they must be standalone and they must not be referenced outside @defer blocks in the same file.

With server-side rendering, the same page explains that @defer blocks show their @placeholder by default, and that to render the main content on the server you need incremental hydration with hydrate triggers: the mechanism is told in full in the article on Angular SSR and incremental hydration (in Italian).

This site already uses @defer: eleven templates contain it, and the most frequent form is @defer (hydrate on viewport), sixteen times (grep -rho "@defer ([^)]*)" src/app --include=*.html | sort | uniq -c | sort -rn). Before adding another you need to know which of the 69 files justifies it.

The path is this: a build with the esbuild statistics file to recognise the chunks, then a before-and-after comparison with the script above. I did not run a build (it takes about 18 minutes), so that step remains open and I do not write what it will find.

What this method does not tell you

  • The processor work to run the script: neither parse time nor execution time.
  • The bytes of third parties, because of the absence of Timing-Allow-Origin.
  • Which route or component corresponds to a chunk: you need the build's names.
  • How much a page loads with a warm cache: every load here starts from a clean context.
  • What it costs on a slow network: mine was not throttled.

The five entries are not defects of the tool: they are the boundary between "how much code arrives" and "how much it costs", and Resource Timing answers only the first question. The most important is the first, because it is the one that reverses decisions: 801 KB over fibre is a detail, the same 801 KB to be parsed on a mid-range phone is the reason a page stands still. The third, instead, is the only one I can remove today without new tools, because a build with the statistics file is enough; the others require a processor profile or a simulated network, that is another article and another method.

Now you can do this

You can count the JavaScript files and kilobytes an Angular SSR page really requests, separate those of your site from those of third parties knowing why the second group shows up as zero, read transferSize for what the specification says it is, compare what the HTML declares with what the browser downloads, and you know what it takes (a build with statistics) to go from "69 files" to "this component".

With the three parts of the series you also have the whole method: timings vary and are reported with median and range (part 1), widths do not vary and are treated as assertions in a test (part 2), counts sit in the middle and change at every publication. The step that remains open is a single one, and I declare it instead of promising it: putting component names next to the 69 files, which requires a build and a before-and-after comparison I did not run here.

Sources

  • PerformanceResourceTiming.transferSize, MDN - the zero value for cross-origin resources without Timing-Allow-Origin, consulted on 2026-11-08
  • Resource Timing, W3C specification - the three cases of transferSize (0 from local cache, 300 if revalidated, compressed body plus 300 otherwise) and §3.5.2 on the Timing-Allow-Origin header, consulted on 2026-11-08
  • Deferrable views, angular.dev - conditions of @defer (standalone, no reference outside the block), behaviour on the server and incremental hydration, consulted on 2026-11-08
  • Measurement on production: node peso-js.mjs as above, Playwright 1.59.1, 2026-11-08
  • Counts in the repository: grep -ro "loadComponent" src/app --include=*routes*.ts | wc -l (737) and grep -rl "@defer" src/app --include=*.html | wc -l (11), 2026-11-08

Of the four entries, the two specifications serve different purposes: the Resource Timing one says how to read a number the API hands me, the Angular one says under which conditions a fix would work. The last two entries are not documentation but measurements of mine, and the difference is worth repeating: a source is consulted, a measurement is rerun. The repository counts (737 and 11) hold for that day's commit and will age; the commands beside them will not.

Commenti

Caricamento commenti...

Sign in to comment

New articles and tools on Telegram too

The Telegram channel flags the site's new articles and tools.

Did you like this article?

Explore other content on the blog or discover my projects