01 — Purpose

JavaScript has real cost

Users pay for every script through download, parse, execution, and battery — most slowness is self-inflicted bundle and hydration weight, not slow networks alone.

JavaScript execution on the main thread competes with user input and rendering. HTML and CSS parsing, style calculation, layout, and paint also consume main-thread time. Reducing script download size helps, but measure execution and rendering work as well. See how browsers render a page.

Many sites can deliver content, forms, and light interaction without SPA complexity. Match the amount of JavaScript to the task.

See JavaScript standard and principles — performance is product quality.

02 — Principles

Every kilobyte should earn its place

The fastest JavaScript is the JavaScript never shipped.

  • progressive enhancement — baseline works without script
  • ship behaviour per page or feature — not one global bundle for everything
  • prefer platform APIs and native HTML before libraries

03 — Practice

Keep cost under control

Split, lazy-load, audit dependencies, and hydrate selectively.

04 — Avoid

Common bloat

Oversized bundles and unnecessary hydration are predictable — and preventable.

  • importing entire libraries for three functions
  • client rendering content that could be static HTML
  • third-party scripts and framework layering nobody questions

05 — Close

Measure on real hardware

Mid-range phones on 4G expose bloat that developer laptops hide.

Set JavaScript budgets per template. Block merges that exceed them without explicit approval.

See Core Web Vitals, third-party performance, and performance review checklist.