awesome-everything RU
↑ Back to the climb

Performance

Bundle budgets: config and output reading

Crux Read real bundler config, import patterns, a size-limit CI snippet, and a Priority header, predict the effect on shipped bytes, and pick the highest-leverage fix.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at senior altitude — in orbit
◷ 14 min

Bundle problems are diagnosed in config files, import lines, the analyzer treemap, and the CI log. Read each snippet the way a senior would, then pick the fix that actually moves shipped bytes — not the one that only moves the wire.

Goal

Practise the loop you run in every bundle review: read the import or config, predict whether it ships dead weight, and reach for the highest-leverage fix — split or shake the bytes before you reach for compression or a knob.

Snippet 1 — the barrel re-export

// components/index.ts
export * from './Button';
export * from './Modal';
export * from './RichTextEditor';   // pulls in a 180 KB editor lib

// consumer
import { Button } from '@/components';   // only Button is used here
Quiz

The route only uses Button, yet the analyzer shows the 180 KB editor in this chunk. What is happening, and what is the fix?

Snippet 2 — the dynamic import

// loads a chart panel that is not on first paint
function openPanel(name) {
  return import(`./panels/${name}`);   // variable in the specifier
}

// elsewhere, a true lazy boundary
const Editor = React.lazy(() => import('./Editor'));
Quiz

Both lines look like code splitting. Which one actually produces a clean, individually-shakeable chunk, and why?

Snippet 3 — the size-limit CI gate

// package.json
"size-limit": [
  { "name": "Homepage JS", "path": ".next/static/**/_app-*.js", "limit": "100 KB" },
  { "name": "All pages total", "path": ".next/static/**/*.js", "limit": "500 KB" }
]
$ npx size-limit
  Homepage JS:     132 KB  (limit 100 KB)   FAIL  +32 KB
  All pages total: 471 KB  (limit 500 KB)   PASS
Quiz

A PR triggers this output. The author asks to merge and 'fix it next sprint'. What is the correct senior response?

Snippet 4 — the HTTP/3 priority

# Browser request for the critical app chunk
GET /_next/static/app.abc123.js
Priority: u=1

# Browser request for a large deferred vendor chunk
GET /_next/static/vendor.def456.js
Priority: u=5

# CDN config (misconfigured): ignores client Priority, serves FIFO
Quiz

The app is correctly code-split and the browser sends sane RFC 9218 priorities, but the CDN ignores them and serves first-come-first-served. What is the likely impact and where do you verify it?

Recap

Every bundle regression is read in config and output: export * barrels and runtime-variable dynamic imports silently defeat splitting and tree shaking; a size-limit failure is a hard gate, not a suggestion to defer; and even a perfectly split bundle underdelivers if the CDN ignores HTTP/3 priorities. Diagnose from the analyzer and the CI log, fix by removing bytes from the critical path first, then confirm delivery order — re-measure rather than assume.

Continue the climb ↑Bundle budgets: cut a route under budget and keep it there
shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources2
expand
  1. 01
  2. 02

Trademarks belong to their respective owners. Editorial reference only.