Performance Budgets in CI: Lighthouse CI and Bundle-Size Gates
Saket Bhatnagar, Founder, SevyDevy, Last updated , 18 min read
Summary
- Performance budgets are limits you set on numbers that decide page speed, such as script bytes or Largest Contentful Paint (LCP, when the main content appears). CI, the server that tests every pull request, then fails any change that crosses them.
- Use two kinds of gate. A bundle-size check (size-limit or webpack's size hints) counts bytes in seconds. Lighthouse CI, a free command-line tool, loads the built page in Chrome and checks timings and resource sizes.
- Byte budgets are steady from run to run, so make them hard failures. Lab timings wobble, so run Lighthouse at least five times and judge the median, the middle value.
- Never gate on the Lighthouse score alone. In our test, a pull request added 74 kB of minified library code, yet the page still scored 100 while the byte budget failed it.
- Beginners can stop after the setup section. Engineers get the part most teams miss: Lighthouse CI judges your best run by default, and the three tools measure the same file differently.
What goes wrong when nobody guards page speed?
Without performance budgets, pages get slower a little at a time, and nobody notices until users complain. Each pull request adds a few kilobytes or a few milliseconds, which looks harmless on its own.
Picture a common setup. A food-ordering web app spent a month making its checkout page fast. Then a developer needed to sort a short list and imported a whole utility library for one function call. The setup is made up, but the numbers in this guide come from real runs.
Nothing broke and every test passed. The checkout script grew from under 100 bytes to 73,608 bytes. Three more changes like that, and the month of speed work is gone.
This slow loss is called a performance regression: a change that makes the product slower than before. Performance budgets in CI are the fix. They turn "keep it fast" into a check that runs on every pull request, the same way unit tests guard correctness.
Which words do you need before setting performance budgets?
You need five words. Each one is explained with the checkout page in mind.
- CI, or continuous integration: a server that builds and tests every pull request automatically before anyone merges it. A failing check blocks or flags the merge.
- Bundle: the JavaScript file your build tool produces by joining your code and its libraries. The checkout bundle here is called main.js.
- Lighthouse: Chrome's free page-testing tool. By default it simulates a slow phone and network, then reports timings, sizes and a score from 0 to 100.
- Lab data vs field data: lab data comes from a test machine like Lighthouse; field data comes from real users' browsers. CI can only produce lab data.
- Core Web Vitals: three field metrics for user experience. They are LCP for loading, INP (Interaction to Next Paint) for responsiveness and CLS (Cumulative Layout Shift) for visual stability.
If those metrics are new to you, the Core Web Vitals guide on this site explains each one and its fixes. This guide is about keeping those wins once you have them.
What are performance budgets?
Performance budgets are agreed limits on the numbers that control how fast a page feels. A budget only helps when a machine checks it on every change and says no when it is crossed.
Think of it like a monthly household budget. You decide in advance that groceries get 8,000 rupees, and every bill is checked against that line. The bundle is the grocery bill, and CI is the person who reads every receipt. Where the picture breaks: a household can overspend and recover next month, but a merged regression usually stays until someone hunts it down.
A web.dev article on performance budgets, last updated in 2018, groups budget metrics into three kinds. Quantity-based budgets cap sizes and counts, such as script bytes or number of requests. Milestone timings cap moments in loading, such as LCP. Rule-based budgets cap a tool's score, such as the Lighthouse performance score.
| Budget kind | Example metric and limit | Tool that checks it | Stable between runs? | What it catches |
|---|---|---|---|---|
| Quantity | Script bytes, 10 kB compressed | size-limit, webpack hints, Lighthouse CI | Yes, same build gives same bytes | A new library or a big import |
| Quantity | Third-party request count, 5 | Lighthouse CI | Usually | A new tag or widget added by marketing |
| Milestone timing | LCP under 2,500 ms in the lab | Lighthouse CI | No, it varies run to run | A slow hero image or render-blocking file |
| Milestone timing | Total Blocking Time under 200 ms | Lighthouse CI | No | Long JavaScript tasks that freeze the page |
| Rule-based | Performance score at least 90 | Lighthouse CI | No | Broad slowdowns, but it can hide byte growth |
Total Blocking Time (TBT) needs one line of explanation. It adds up how long the main thread was blocked by long tasks during loading. The web.dev Core Web Vitals page calls it a lab proxy for INP, because Lighthouse loads pages without a user and cannot measure real input.
How do performance budgets in CI stop a regression?
A CI budget check builds the pull request, measures it, and compares each number with its limit. If any limit with error level is crossed, the job exits with a non-zero code and the check turns red.
Follow the diagram from the pull request down. Notice that the cheap byte check runs first. A red result there skips the slower Lighthouse runs.
A pull request passing through two budget gates
Drag to exploreThe fast byte gate runs before the slower browser gate. Either one can stop the merge on its own.
Diagram connections:
- Pull request opened to CI builds the site
- CI builds the site to size-limit check
- size-limit check to Lighthouse CI collect (Bytes pass)
- size-limit check to Check is red (Bytes over limit)
- Lighthouse CI collect to Lighthouse CI assert
- Lighthouse CI assert to Within every budget?
- Within every budget? to Check is green (Yes)
- Within every budget? to Check is red (No)
- Pull request opened: Developer adds a utility library
- CI builds the site: npm ci, then npm run build into dist
- size-limit check: Compresses main.js and compares to 10 kB
- Lighthouse CI collect: Loads the built page 5 times in Chrome
- Lighthouse CI assert: Checks median LCP, TBT, CLS and script bytes
- Within every budget?: Any error-level failure means no
- Check is green: Review and merge as usual
- Check is red: Report shows which budget broke
The two gates do different jobs. The byte gate is cheap and exact, so it catches most regressions in seconds. The browser gate catches what bytes miss, such as a render-blocking font or an image that delays LCP.
How do you set a bundle-size budget with size-limit?
Install size-limit and its file plugin, list each file with a limit, and run it in CI. It exits with code 1 when any file is over its limit.
We tested size-limit 14.2.0 with @size-limit/file 14.2.0, installed pinned with npm. The config lives in a file called .size-limit.json at the project root:
[
{
"name": "Checkout script",
"path": "dist/main.js",
"limit": "10 kB"
}
]On the clean checkout build, the run printed a size of 85 B brotlied and passed. After the pull request imported the whole lodash 4.17.21 library for one sort, the same command printed this and exited with code 1:
Package size limit has exceeded by 13.92 kB
Size limit: 10 kB
Size: 23.92 kB brotlied
Try to reduce size or increase limit at .size-limit.jsonRead the units carefully. The file plugin compresses with Brotli at its highest quality by default. In the source of size-limit 14.2.0, "kB" means 1,000 bytes and "KiB" means 1,024 bytes.
- Set gzip to true on a check if your server sends gzip instead of Brotli.
- Set brotli to false to measure the raw file on disk.
- Add @size-limit/time if you also want the time to run the script, measured in headless Chrome.
- The size-limit README also points to a GitHub Action that comments size changes on each pull request.
The webpack option if you already use webpack
webpack has a built-in size gate called performance hints. Set performance.hints to "error" and set maxAssetSize and maxEntrypointSize in bytes. The webpack docs give a default of 250,000 bytes for both.
In production mode the default is a warning, which does not fail the build on its own. We ran webpack 5.110.3 with hints set to error, a 20,000-byte limit and minification turned off. The 535 KiB lodash build failed with "asset size limit" errors and exit code 1.
One catch: webpack compares the emitted file size, before any compression. In our test the minified file was about three times its Brotli size, so webpack limits need to be set much higher.
How do you set up Lighthouse CI 0.15 with performance budgets?
Add a lighthouserc.json file, point it at your build folder, list your assertions, and run lhci autorun in CI. Assertions are Lighthouse CI's name for budget rules.
Our build step was esbuild 0.28.2 bundling and minifying the checkout code into dist/main.js, next to the page's HTML file. Any bundler works, as long as the dist folder holds the built HTML.
We ran @lhci/cli 0.15.1, the latest release as of 31 October 2026, against the checkout build with Chrome for Testing 153. This is the exact config that ran:
{
"ci": {
"collect": {
"staticDistDir": "./dist",
"numberOfRuns": 5
},
"assert": {
"assertions": {
"largest-contentful-paint": [
"error",
{
"maxNumericValue": 2500,
"aggregationMethod": "median"
}
],
"total-blocking-time": [
"error",
{
"maxNumericValue": 200,
"aggregationMethod": "median"
}
],
"cumulative-layout-shift": [
"error",
{
"maxNumericValue": 0.1,
"aggregationMethod": "median"
}
],
"resource-summary:script:size": [
"error",
{
"maxNumericValue": 10000
}
],
"categories:performance": [
"warn",
{
"minScore": 0.9
}
]
}
},
"upload": {
"target": "filesystem",
"outputDir": "./lhci-report"
}
}
}Here is what each part does, in plain words:
- staticDistDir points at the folder with your built HTML. Lighthouse CI starts its own small web server for it, so you do not need one.
- numberOfRuns sets how many times each page loads. The default is 3; we use 5 for steadier medians, explained in the next section.
- Each assertion names a Lighthouse audit, a level and a limit. maxNumericValue is a ceiling; minScore is a floor between 0 and 1.
- The level error fails the job. The level warn prints the problem but keeps the exit code at 0, which we confirmed by running both.
- resource-summary:script:size is the byte budget for all scripts on the page. The general pattern is resource-summary, a resource type, then size or count.
- upload with target filesystem saves the HTML reports into a folder you can keep as a CI artifact.
On the clean build, all five runs passed. We also ran it on the lodash build, skipping the size-limit step. It failed on script bytes only. This is the trimmed output:
Checking assertions against 1 URL(s), 5 total run(s)
✘ resource-summary.script.size failure for maxNumericValue assertion
found: 27856
all values: 27856, 27856, 27856, 27856, 27856
Assertion failed. Exiting with status code 1.We removed one line that repeats the 10000-byte limit, because it uses a symbol this site cannot show. The found value is the script transfer size in bytes.
To wire both gates into GitHub Actions, add a workflow like the one below. The action versions match the official READMEs as of 31 October 2026. We ran every command in it locally, but not this exact workflow file on GitHub.
name: performance-budgets
on: [pull_request]
jobs:
budgets:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 22
- run: npm ci
- run: npm run build
- name: Bundle-size budget
run: npx size-limit
- name: Lighthouse CI budget
run: npx lhci autorunPin @lhci/cli and size-limit as exact devDependencies in package.json. Then npx runs the version you tested, not whatever is newest on the day of the build.
Why the Lighthouse score alone let the regression through
The lodash build scored 100 for performance in all three runs of our first test. LCP stayed near 630 ms. Our test page is tiny, with one heading and one script, so the extra bytes did not move its lab timings.
Only the byte budget saw the 74 kB jump. On a real checkout page with images, fonts and other scripts, the same import would add to an already heavy load. A score gate tends to react only when the whole page is already slower. A byte gate reacts to the first step.
Why do Lighthouse CI timing budgets pass on bad code?
Because, by default, Lighthouse CI judges the best of your runs. Its default aggregation method, the rule for turning several runs into one number, is "optimistic", which picks the value most likely to pass.
Lab timings change between runs even when the code does not. On the unchanged clean build, our five LCP results ranged from 629 to 888 ms. Total Blocking Time ranged from 0 to 39 ms.
To see the effect, we re-checked one saved set of three runs against a TBT limit of 40 ms. The three values were 2.5, 42.5 and 78 ms. Only the aggregation method changed between checks.
Pause and predict: with the limit at 40 ms, which of the four methods lets this build pass? Two of the three runs were over the limit.
| aggregationMethod | Value it compares | Result | When to use it |
|---|---|---|---|
| optimistic (default) | 2.5 ms, the best run | Pass | Almost never for timings; it hides noise and real slowdowns |
| median | 42.5 ms, the middle run | Fail | Default choice for timing budgets |
| median-run | 42.5 ms, from the most typical run | Fail | When you want all metrics from one real run |
| pessimistic | 78 ms, the worst run | Fail | Strict gates on very stable, dedicated machines |
So set aggregationMethod to median on every timing assertion, as in our config. Byte assertions do not need it, because the same build gave 27,856 bytes in all five runs.
The Lighthouse variability guide says the median Lighthouse score of 5 runs is twice as stable as a single run. It also warns that free CI machines are typically quite volatile. It suggests dedicated machines with at least 2 cores, and never running two Lighthouse reports at once on one machine.
How five noisy runs become one pass or fail
Drag to exploreThe same build gives different timings each run. The aggregation method decides which run the budget sees.
Diagram connections:
- One built checkout page to Five Lighthouse runs
- Five Lighthouse runs to Which aggregation?
- Which aggregation? to Best run (optimistic) (Nothing set)
- Which aggregation? to Middle run (median) (median)
- Best run (optimistic) to Pass or fail the check
- Middle run (median) to Pass or fail the check
- One built checkout page: Same code for every run
- Five Lighthouse runs: Our LCP results: 629 to 888 ms
- Which aggregation?: Set per assertion in lighthouserc.json
- Best run (optimistic): Default: noise and slowdowns can pass
- Middle run (median): Steadier: one lucky run cannot pass it
- Pass or fail the check: Compared with maxNumericValue
Why do size-limit, webpack and Lighthouse CI report different sizes for one file?
Each tool measures a different version of the same bytes. Knowing which one you set a limit on prevents budgets that are ten times too loose or too strict.
| Tool | What it measures | Number we got | Set limits in |
|---|---|---|---|
| webpack performance hints | Emitted file on disk, no compression | 73,608 bytes for the minified file | Raw bytes |
| size-limit file plugin | File compressed with Brotli at top quality | 23,920 bytes (shown as 23.92 kB) | Compressed bytes |
| Lighthouse CI resource-summary | Transfer size over the network, including headers | 27,856 bytes | Bytes as sent by its server |
Lighthouse CI's number depends on the server. Its built-in static server turns on gzip compression, and the size includes HTTP headers. A clean build with a 98-byte script still showed a 448-byte transfer.
If you test a live staging URL instead, your CDN's compression decides the number. Measure once on the clean build before you write any limit.
What changed in Lighthouse budget.json support?
Lighthouse itself no longer runs budgets: version 12.0.0, released on 22 April 2024, lists "remove budgets" among its breaking changes. Lighthouse CI still accepts a budget.json file through its budgetsFile option.
We read how in the source of @lhci/utils 0.15.1. Lighthouse CI converts each budget into resource-summary assertions itself. Resource sizes in budget.json are in KiB, so a script budget of 10 became a limit of 10,240 bytes in our run.
- budgetsFile cannot be mixed with assertions; the code throws "Cannot use both budgets AND assertions".
- Every converted budget is error level, so you cannot mark one as a warning.
- Timing entries become plain assertions with the default optimistic method, so they judge the best run.
For new projects, write assertions directly. You get levels, medians and score checks in one place.
How do you choose the first budget numbers?
Measure the main pages on the current main branch, then set each limit slightly above today's value. The goal of the first budget is to stop things getting worse, not to make them better.
Pick two or three key pages
Choose pages that earn money or get the most visits, such as home, product and checkout. Budget those first.
Measure the clean build
Run size-limit once and Lighthouse CI with five runs. Write down compressed script bytes, median LCP and median TBT.
Add small headroom
Set byte limits about 5 to 10 percent above today, and timing limits a little more, to absorb noise.
Start timing checks as warn
Keep byte checks at error from day one. Move timing checks to error once a week of runs shows they are steady.
Ratchet after every win
When a speed fix lands, lower the limit in the same pull request so the gain cannot slip back.
Name an owner for exceptions
When a feature truly needs more bytes, raise the limit in its own reviewed change, with the reason in the commit.
Keep the field data in view as well. CI budgets catch changes early, but Core Web Vitals are judged on real users at the 75th percentile. The "good" limits are LCP within 2.5 seconds, INP of 200 ms or less, and CLS of 0.1 or less.
How do you explain performance budgets in a system design interview?
Present them as a guardrail around the frontend, with separate checks for bytes, lab timings and real users.
Define the budget
Say it is a limit on numbers that drive speed, checked on every pull request, like tests for correctness.
Name the metrics
Pick compressed script bytes, request counts and lab timings like LCP and TBT. Explain that TBT stands in for INP in the lab.
Place the gates
A fast bundle-size check first, then Lighthouse CI on the built page. Both fail the job on error-level breaches.
Handle noise
Run several times, judge the median, and keep timing headroom. Mention that the default optimistic method judges the best run.
Close the loop with users
Field Core Web Vitals at the 75th percentile tell you whether the lab budgets are the right ones.
Questions people ask
What is a performance budget in web development?
A performance budget is a set of limits on numbers that affect page speed, such as script bytes, request counts, LCP or a Lighthouse score. Teams check those limits automatically on every change. A pull request that crosses an error-level limit fails its CI check, so slowdowns are caught before they reach users.
Is Lighthouse CI free to use?
Yes. Lighthouse CI is an open-source command-line tool installed from npm as @lhci/cli, and it runs on your own CI machines. You can keep reports on disk or run your own Lighthouse CI server. Be careful with the temporary public storage option, because anyone with the link can open those reports.
Should a performance budget fail the build or only warn?
Make byte budgets fail the build, because the same code gives the same bytes every time. Start timing budgets as warnings, since lab timings vary between runs. Once a week of results shows they are steady and judged on the median, switch them to errors too.
How many Lighthouse runs do you need in CI?
Use at least five runs per page and compare the median. Lighthouse CI's default is three runs, and its default method picks the best run. The Lighthouse variability guide says the median score of five runs is twice as stable as one run.
Can Lighthouse CI measure INP?
No. Lighthouse loads pages without a user, so there is no click or key press to measure. Use Total Blocking Time as the lab stand-in, which web.dev calls a proxy for INP. Measure real INP with field data from real users.
What is a good JavaScript size budget?
There is no single right number. Start just above what your key page ships today, measured compressed, so the current build passes. Then lower the limit each time you remove code. An old web.dev example used 170 KB of JavaScript for a mobile product page, but your own measurement is the better guide.
Does budget.json still work in Lighthouse?
Not in Lighthouse itself, which removed budgets in version 12.0.0 in April 2024. Lighthouse CI 0.15.1 still reads a budget.json file through budgetsFile and turns it into resource-summary assertions. Direct assertions are the better choice for new projects, because they support warnings and medians.
Keep learning
Practise it with Lala
A question on this guide, hints and a review.
Read next
Sources (9)
- Lighthouse CI docs: configuration (assertions, aggregation methods, budgetsFile)
- Lighthouse CI docs: getting started (GitHub Actions, status checks, temporary public storage)
- Lighthouse v12.0.0 release notes (remove budgets)
- Lighthouse docs: score variability
- web.dev: Performance budgets 101
- web.dev: Web Vitals (thresholds and TBT as a lab proxy for INP)
- webpack docs: performance hints configuration
- size-limit README
- @lhci/cli package on npm (version 0.15.1 tested)