Skip to content

Measure the initial bundle in CI and hold it to a budget - #44

Merged
aevnsvi merged 3 commits into
mainfrom
bundle-size-budget
Nov 8, 2026
Merged

aevnsvi merged 3 commits into
mainfrom
bundle-size-budget

Conversation

@aevnsvi

@aevnsvi aevnsvi commented Nov 8, 2026

Copy link
Copy Markdown

What changes

  • scripts/bundle-size.mjs measures the initial load: the gzip size (level 9) of every script and stylesheet that dist/index.html names, added up. It has no dependency beyond Node built-ins and refuses an asset path that would leave the dist folder.
  • The limit is initialGzipBytes in config/bundle-budget.json. The check exits 1 over the limit and the message names that file, so raising the limit is an explicit change in a pull request. Missing or invalid input exits 2.
  • Every other script and stylesheet chunk is reported with raw and gzip size in the job log and, when GITHUB_STEP_SUMMARY is set, in the job summary. They are not budgeted.
  • The pr-checks job gets two steps after Checks: Build UI for the bundle size and Bundle size. It runs on every pull request and every push to main. The smoke workflow and the required checks are unchanged.
  • The README describes the check and how to see the numbers locally.

How the limit was set

The limit is the measured initial load times 1.10, rounded up to the next 1,000 bytes. The local build measures 448,089 bytes gzip (242,892 script, 205,197 stylesheet), which gives 493,000.

How it is tested

scripts/bundle-size.test.mjs covers parsing of quoted and unquoted attributes, the sum, the comparison, the refusal of a path outside dist, the exit codes 0, 1 and 2 through the command line, and the Markdown summary. The check was also run on the real build, and with a limit 1,000 bytes below the measurement it exits 1.

- scripts/bundle-size.mjs sums the gzip size of every script and stylesheet
  index.html names, compares it with config/bundle-budget.json and reports
  every other chunk with raw and gzip size
- exit status 1 over the budget, 2 for missing or invalid input or an asset
  path outside the dist folder
- the report is appended to the job summary when GITHUB_STEP_SUMMARY is set
The pr-checks job builds the production bundle and runs the size check
against config/bundle-budget.json on every pull request and every push to
main. The README describes the check and how to see the numbers locally.
The pull request check measures 448,486 bytes gzip on the CI runner, a few
hundred bytes more than a local build. The limit is that number plus 10
percent, rounded up to the next 1,000 bytes.
@aevnsvi
aevnsvi merged commit d93e4b8 into main Nov 8, 2026
6 checks passed
@aevnsvi
aevnsvi deleted the bundle-size-budget branch November 8, 2026 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant