HTTP, TLS & Web Performance

Performance Budgets: Keeping Sites Fast Over Time

Set clear limits for page weight and speed, check them automatically, and decide what happens when a change breaks the budget.

Key takeaways

  • A budget turns speed from a one-off cleanup into a rule that every new feature has to respect.
  • Combine a few limits you can check on every change, such as file sizes, with user-centered timing measured on real visits.
  • Set the first budget close to current performance so it stops regressions, then tighten it in steps.
  • Budgets differ by page type, because a checkout form and a photo gallery have different jobs.
  • A limit without an owner and an agreed response will be ignored the first time it is inconvenient.

A performance budget is a limit you agree on in advance, such as "no more than 170 KB of compressed JavaScript on an article page" or "main content visible within 2.5 seconds for most mobile visitors". When a change would cross the line, someone has to make a decision before it ships instead of discovering months later that the site has become slow.

To set one up, measure where you are, choose a few limits that matter to visitors, check them automatically and agree on what happens when a check fails.

Why sites get slow gradually

Few teams decide to build a slow site. It happens through a series of reasonable choices: a new chart library, an extra font weight, a chat widget, a campaign banner, another measurement tag. Each adds little, and nobody sees the total.

After a cleanup, the same forces keep working. Without a guard, the gains from a performance audit tend to fade within a few release cycles.

A budget makes the cost visible at the moment of choosing. "This widget uses a third of our remaining script allowance" is a much better conversation than "the site feels sluggish lately".

Three kinds of budget

Quantity budgets limit what you send: bytes of JavaScript, CSS, images and fonts, or the number of requests and third-party origins. They're easy to check during a build and point directly at the cause.

Timing budgets limit what visitors experience: Largest Contentful Paint, Interaction to Next Paint, First Contentful Paint, Time to First Byte. They matter most, but they vary with devices and networks. The Core Web Vitals thresholds make sensible outer limits.

Rule or score budgets require a minimum audit score, or forbid specific problems such as images without dimensions. They're convenient, though a composite score can hide which thing changed.

What each kind of budget is good at
Quantity Stable from run to run Checkable before release Points at the file responsible Can miss slow server work Timing Reflects what people feel Needs lab runs or real user data Noisier, so use medians or percentiles Cause takes investigation Rules and scores Quick to adopt with existing tools Catches known mistakes Scores shift when tools are updated Easy to game without helping anyone Quantity Stable from run to run Checkable before release Points at the file responsible Can miss slow server work Timing Reflects what people feel Needs lab runs or real user data Noisier, so use medians or percentiles Cause takes investigation Rules and scores Quick to adopt with existing tools Catches known mistakes Scores shift when tools are updated Easy to game without helping anyone

A good starting set is one quantity budget for scripts, one for total page weight, and one or two timing limits.

Setting the numbers

Begin with measurement. Record the transfer size by type and the main timings for each important page template.

Then choose the first limits by one of these routes:

  1. Hold the line. Set the budget slightly above today's figures. Nothing gets worse.
  2. Work back from a goal. Decide on a target device and connection, then estimate how much data and processing fit within your time target.
  3. Compare with peers. Measure similar sites under the same conditions and aim to be competitive.

A rough calculation helps with the second route. On a connection delivering about 1.6 megabits per second, which is 200 kilobytes per second, three seconds of pure transfer is at most about 600 KB. Real pages get less, because connection setup, server time, round trips and processing all take a share. A data rate and transfer time planner makes this kind of arithmetic quick.

Remember that bytes aren't equal. A kilobyte of JavaScript usually costs more than a kilobyte of image, since the script has to be parsed and run on the visitor's processor.

Example budget for an article page, compressed
Images above the fold 200KB JavaScript 150KB Fonts 80KB CSS 40KB HTML 30KB Images above the fold 200KB JavaScript 150KB Fonts 80KB CSS 40KB HTML 30KB

Your own limits should come from your measurements and audience. Hypothetical example: the numbers are made up to show the method, not a quote or an average.

One site, several budgets

Group pages by template. An article page can be held to a strict script limit. A product configurator needs more code, but you might insist that its first view appears quickly and defer the rest with lazy loading.

Separate your own code from third parties. Giving external tags their own allowance means marketing and product teams can see their share and trade one tag for another within it.

Writing the budget down

A budget works best as a short document that lives with the code. For each page template, list the metric, the limit, how it's measured and under what conditions. "JavaScript, compressed, first load, article template" is a limit two people will read the same way. "Keep scripts light" is not.

State the test conditions precisely. A byte limit needs to say whether it counts compressed transfer or uncompressed files, and whether items loaded after the page is usable are included. A timing limit needs the device profile, network profile, number of runs and which statistic you take. Without those details, a failure turns into an argument about the measurement.

Add the reason for each number in a sentence. A future colleague who understands that the script limit protects responsiveness on modest phones is more likely to respect it, or to revise it sensibly when circumstances change.

Finally, name a representative page for each template. A budget tested against a nearly empty sample article will pass forever while real articles, with embeds, galleries and long comment threads, drift well past it. Choose a page that's on the heavy side of normal and refresh the choice now and then.

Automating the checks

A budget that depends on someone remembering to look won't last. Add checks where changes happen.

Many bundlers can warn or fail when an output file passes a size. In webpack, for example:

performance: {
  hints: 'error',
  maxAssetSize: 150000,
  maxEntrypointSize: 250000
}

These sizes are in bytes of the uncompressed output, so set them with that in mind.

For lab timing, Lighthouse CI runs audits in your build pipeline and compares the results with assertions you define. A configuration file looks something like this:

{
  "ci": {
    "collect": { "numberOfRuns": 5, "url": ["http://localhost:8080/article.html"] },
    "assert": {
      "assertions": {
        "largest-contentful-paint": ["error", { "maxNumericValue": 2500 }],
        "total-byte-weight": ["warn", { "maxNumericValue": 800000 }]
      }
    }
  }
}

Check the tool's documentation for current option names. You can also write a very small script that sums the compressed size of files in your build folder and exits with an error above a threshold. Simple checks are often the most durable.

For field timing, set alerts on your real user monitoring when the 75th percentile crosses a limit for several days.

Where in the workflow to check

Different checks belong at different moments. Size checks are fast, so run them on every change and show the difference from the main branch: an added 40 KB is easier to question when it's printed beside the change that caused it. Lab timing takes longer and can run on proposed merges or a nightly schedule against a staging copy. Field alerts run continuously on the live site and catch what the others can't, such as a campaign tag added through a tag manager or an unusually large upload from the editing team.

Make failure messages helpful. State the limit, the new value, the size of the increase and the largest files involved. A message that only says "budget exceeded" sends someone hunting.

Tag managers deserve a special note, because they change a live page without going through your pipeline at all. Limit who can publish in them, and include a weekly lab run of production pages so an added tag is noticed within days.

Dealing with noise

Timing results vary even when nothing changes. Shared build machines are especially uneven. Reduce false alarms by running several times and using the median, pinning tool versions, testing against a stable environment with fixed data, and removing live third-party content from lab runs or measuring it separately.

Use two levels. A warning threshold invites a look, and a failure threshold blocks the release. If a check cries wolf weekly, people will switch it off.

When the budget is exceeded

Decide the response before it happens. The usual options are:

A change breaks the budget
Can the new code or asset be made smaller? YES Optimize it and re-run the check. 1 NO Can it load only when someone needs it? YES Defer it out of the initial load. 2 NO Is there something older that can be removed? YES Trade it out and stay within the limit. 3 NO Is the value clearly worth the slower page? YES Raise the limit on record, with an owner and review date. 4 NO Don't ship it yet The cost is higher than the benefit as it stands. Can the new code or asset be made smaller? 1 IF YES Optimize it and re-run the check. NO Can it load only when someone needs it? 2 IF YES Defer it out of the initial load. NO Is there something older that can be removed? 3 IF YES Trade it out and stay within the limit. NO Is the value clearly worth the slower page? 4 IF YES Raise the limit on record, with an owner and review date. NO Don't ship it yet The cost is higher than the benefit as it stands.

Exceptions are fine when they're explicit. Quiet increases are how a budget stops meaning anything. Keep a short log of each change to the limits, with the reason.

What can go wrong

  • Too many metrics. Twenty limits produce constant failures that nobody reads.
  • Limits nobody believes. A target far below current performance fails on day one and gets disabled.
  • Gaming the number. Moving code to load a second after measurement ends helps the report, not the visitor.
  • Ignoring content. Editors can upload a huge image after every build check has passed. Enforce resizing at upload and monitor live pages.
  • Forgetting the server. Byte budgets say nothing about a slow database query, so keep a first-byte limit too.

Making it part of the culture

Show the numbers where people already look, such as the pull request or a shared dashboard. Include speed cost in the discussion when a feature or vendor is proposed, before anyone has built anything.

Celebrate removals. Deleting an unused library earns back allowance for future work. And revisit the budget a few times a year, since audiences, devices and the site's purpose all change. Good defaults help too: if your templates already apply efficient image formats, compression and sensible cache headers, most new pages will start well inside the limits.

Rolling it out on an existing slow site

If your site already misses every target, don't start by failing every build. Set the limits at current values, which immediately stops the slide. Then plan reductions, one template or one resource type at a time, and lower the limit after each success so the gain is locked in. This ratchet approach gives people regular wins and avoids a single enormous rewrite that keeps being postponed.

Common questions

Who should own the budget?

Whoever can say no to a release, or at least delay it. In a small team that might be the developer responsible for the front end, with the site owner deciding on exceptions.

Is a budget worthwhile for a small brochure site?

A light one is. A note saying "pages stay under a certain size and we check after each change" takes minutes and catches the oversized photo or the forgotten video background.

Written for 4Internet with AI writing tools and not reviewed line by line by a person. Check anything you rely on with the maker, provider or standard concerned. Report an error.

Keep reading

All 45 articles in HTTP, TLS & Web Performance →

Latest news on this topic