Writing a Performance Budget That Fails Builds

A performance budget is only useful if it fails the build at the right moment: not on every pull request because the numbers were aspirational, and not never because they were so loose nothing could cross them. Getting there means deriving numbers from your own site, setting them per template, choosing which limits are hard errors and which are warnings, and tightening them on a schedule rather than in a burst of enthusiasm.

This guide builds a budget for a Hugo marketing and documentation site with four templates, encodes it for Lighthouse CI, and shows six months of how it behaved. It builds on the concepts in Performance Budgets and Lighthouse CI and assumes the wiring from Setting Up Lighthouse CI for a Static Site.

Prerequisites

  • Lighthouse CI running against preview deploys, or at least locally against the built site.
  • A list of your templates and one representative URL for each.
  • Field data for context if you have it — CrUX or your own real-user monitoring.

Step 1: Measure Where You Are

Run Lighthouse five times against each template's representative URL on the same infrastructure CI will use, and record the medians. Resource sizes come from the resource-summary audit; timings from the metrics.

for url in / /pricing/ /docs/getting-started/ /blog/2026/launch/; do
  npx -y @lhci/cli@0.14.x collect --url="$PREVIEW$url" --numberOfRuns=5 >/dev/null
done
npx -y @lhci/cli@0.14.x assert --preset=lighthouse:no-pwa --no-lighthouserc > baseline.txt || true
node scripts/lhci-medians.mjs .lighthouseci > baseline.json

The baseline for the four templates:

TemplateScript KBCSS KBImage KBFont KBRequestsLCP (s)TBT (ms)CLS
Home642218871242.11200.02
Pricing71224671211.61500.01
Docs page18221248121.2200.00
Blog post222214271171.9400.04

The table already argues against a single site-wide budget. A 70 KB script limit is tight for pricing and four times too loose for docs, where an accidental 40 KB dependency would pass unnoticed.

Step 2: Set Limits per Template

For each template and metric, set the warning at today's value rounded up, and the error roughly 10–15% above it for bytes and 20% above it for timings, which vary more. Where today's value is already above a sensible absolute limit — say, LCP above 2.5 s — set the error at the absolute limit and plan the fix.

Lighthouse's native budget.json expresses byte and count limits per path:

[
  {
    "path": "/docs/*",
    "resourceSizes": [
      { "resourceType": "script", "budget": 25 },
      { "resourceType": "stylesheet", "budget": 26 },
      { "resourceType": "font", "budget": 55 },
      { "resourceType": "image", "budget": 40 },
      { "resourceType": "total", "budget": 150 }
    ],
    "resourceCounts": [{ "resourceType": "total", "budget": 15 }],
    "timings": [
      { "metric": "largest-contentful-paint", "budget": 1500 },
      { "metric": "total-blocking-time", "budget": 60 }
    ]
  },
  {
    "path": "/blog/*",
    "resourceSizes": [
      { "resourceType": "script", "budget": 30 },
      { "resourceType": "image", "budget": 180 },
      { "resourceType": "total", "budget": 330 }
    ],
    "timings": [{ "metric": "largest-contentful-paint", "budget": 2300 }]
  }
]

Sizes are in kilobytes of transfer size and timings in milliseconds. Paths match with a trailing wildcard, and the first matching entry wins, so list specific paths before general ones.

Script budgets per template against today's values Four templates with today's script bytes, warning and error thresholds. Home: 64 KB today, warn 65, error 72. Pricing: 71 today, warn 72, error 80. Docs: 18 today, warn 20, error 25. Blog: 22 today, warn 24, error 30. A single site-wide limit of 80 KB is drawn for comparison, which would let docs pages grow more than fourfold unnoticed. Script KB: today (bar), warn (tick), error (line) one site-wide limit: 80 KB Home Pricing Docs 18 KB today · 4.4× headroom under a site-wide limit Blog scale: 7 px per KB · warn ≈ today rounded up · error ≈ +10–15%
Per-template limits sit just above each template's reality; a single site-wide limit is only ever tight for the heaviest page.

Step 3: Decide Error Versus Warning

Not every limit should block a merge. The rule that worked here:

  • Errors: byte and request budgets (deterministic, so a failure is always real), CLS (small spread in practice), and rule audits such as unsized-images and font-display.
  • Warnings initially, errors later: LCP and TBT. After four weeks of results, compute each metric's spread across unchanged builds; once the error threshold sits more than two spreads above the median, promote it to an error.

In Lighthouse CI this becomes a combination of budgetsFile and explicit assertions:

// lighthouserc.js (assert section)
assert: {
  budgetsFile: './budget.json',        // byte/count limits → errors
  assertions: {
    'performance-budget': 'error',
    'timing-budget': 'warn',           // promote after four weeks
    'cumulative-layout-shift': ['error', { maxNumericValue: 0.1 }],
    'unsized-images': 'error',
    'font-display': 'error',
  },
},
When a timing warning becomes an error A timeline of four weeks. In weeks one to four, LCP on the docs template is recorded as a warning while its spread across unchanged builds is measured at about 120 milliseconds around a 1.2 second median. The error threshold of 1.5 seconds sits 2.5 spreads above the median, so at week four the assertion is promoted to an error. Promote timing limits only once their noise is known week 1 week 2 week 3 week 4 median 1.2 s ± 0.12 s spread error threshold 1.5 s (2.5 spreads above) assertion level: warn error Docs template, median of 3 runs per build, unchanged builds only
Promoting after the noise is measured means the first timing error the team sees is a real one.

Step 4: Ratchet Down Each Quarter

A budget that only ever rises is a record of decline. Every quarter, compare each limit with the template's actual values over the period. Where a template stayed well under its limit the whole time — more than 15% headroom — lower the limit to the new reality plus the usual margin. A short script reads the stored Lighthouse CI results and prints proposed new limits; a human reviews and commits them.

Proposed budget changes (Q3)
  /docs/*   script   25 → 22 KB   (max seen 19.4)
  /docs/*   LCP      1500 → 1400 ms (p95 of medians 1.26 s)
  /blog/*   image    180 → 160 KB (max seen 138)
  /         (no change — within 8% of limits)

Ratcheting is what turns one-off optimisation work into a permanent gain. Without it, the next regression can quietly consume the headroom the optimisation created.

A ratcheting script budget over three quarters A step line for the docs template's script budget falling from 25 kilobytes in quarter one to 22 in quarter two and 20 in quarter three, with the measured script size below it falling from 18 to 16 kilobytes. Without the ratchet, a flat 25 kilobyte limit would have left 9 kilobytes of unused headroom for regressions. Docs template script budget, quarter by quarter 10 KB 20 KB 30 KB flat limit 25 KB (no ratchet) 25 KB 22 KB 20 KB measured: 18 → 16 KB Q1 Q2 Q3
The gap between the red limit and the green reality is the space a regression can hide in; the ratchet keeps it small.

The ratchet also changes how optimisation work is valued. When a developer trims 3 KB from the docs template, the next quarterly review turns that saving into a lower limit, so the gain is protected rather than silently spent by the next feature.

Measured Impact

Six months on the four-template Hugo site:

MeasureValue
Pull requests checked318
Budget errors29 (all real regressions)
Timing warnings52 (8 led to a fix; the rest were within noise)
Timing limits promoted to error3 of 4 templates after week four
Limits lowered by quarterly ratchet9
Docs template script bytes, start → end18 KB → 16 KB
Field LCP p75 (CrUX, mobile), start → end2.0 s → 1.7 s

No byte-budget error in six months was a false alarm, which is the property that kept the team trusting the check.

Common Budget Mistakes

Four mistakes account for most budgets that get abandoned. Aspirational numbers: setting the docs LCP limit to 1.0 s because it sounds good, when today's median is 1.2 s, produces a check that fails on every pull request until someone disables it. Counting the wrong bytes: resourceSizes are transfer sizes, so a budget copied from a tool that reports uncompressed sizes will be roughly three times too loose for text assets. Forgetting third parties: scripts loaded from other origins count towards the page's totals, and a vendor update can push a template over its limit without any change in your repository; a nightly run against production, as described in Auditing Third-Party Scripts with Lighthouse, catches those. No owner: someone must review warnings weekly and run the quarterly ratchet, or both quietly stop.

Pitfalls & Rollback

  • Wildcard order. budget.json uses the first matching path. Put /docs/api/* before /docs/*, or the API pages inherit the wrong limits.
  • Budgets on uncompressed sizes. Lighthouse measures transfer size. Compare like with like when copying numbers from bundler output.
  • Raising limits silently. Require a reason in the commit message and approval from the budget owner for any increase.
  • Ignoring warnings forever. A warning nobody reads is noise. Review them weekly, or delete the ones that never lead to action.
  • Rollback: the budget is two files. Reverting a limit change is a one-line diff; demoting an assertion from error to warn makes it advisory without removing the data.

Conclusion

A performance budget that fails builds usefully is built from your own numbers, set per template, split into deterministic errors and measured-noise warnings, and ratcheted down every quarter. On this four-template site that produced 29 build failures in six months, every one a real regression, and a field LCP that improved from 2.0 to 1.7 seconds instead of drifting the other way.

FAQ

Where should the first budget numbers come from?

From your own site's current measurements, plus a small margin. Measure each template with the median of several Lighthouse runs, set the error threshold about 10 percent above today's value and the warning threshold at today's value, then tighten as you fix things.

Should every template share one budget?

No. A homepage with a hero image and a text-only reference page have different realistic limits. Use per-path budgets so each template is held to a limit it can actually meet, and one heavy template cannot hide regressions in light ones.

What is the difference between budget.json and Lighthouse CI assertions?

budget.json is Lighthouse's native format for resource sizes, request counts and timings per path. Lighthouse CI assertions can check those budgets and any other audit or metric. Many teams use budget.json for bytes and assertions for metrics and rules.

How often should budgets be tightened?

Quarterly works well. Review the headroom each template has against its limits, and lower any limit where the template has sat comfortably below it for the whole quarter.