Skip to content
Performance & Accessibility

JavaScript Performance: What Actually Works

The cost of the scripts a page ships: downloading, parsing, compiling and executing them.

Marcus Adeyemi Technical Director 2 min read 20 views
JavaScript Performance: What Actually Works

Where most projects go wrong

The usual mistakes:

  • One bundle for the whole application
  • Large libraries imported for a single function
  • Polyfills served to browsers that do not need them
  • Benchmarking only on fast hardware

What good looks like instead

  • Ship less JavaScript before optimizing what you ship
  • Split by route so pages do not carry unrelated code
  • Audit dependencies for large libraries used for small purposes
  • Break long tasks and yield to the main thread
  • Measure on a mid-range device, not a workstation
What to do and what to avoid with JavaScript performance, side by side
Good practice against the usual mistakes, from the sources listed below.

Why it matters

JavaScript is byte for byte the most expensive resource on a page, because unlike an image it has to be parsed and executed as well as downloaded.

The specs that matter

Published figures for JavaScript Performance
MeasureFigure
Costdownload, parse, compile and execute, on the main thread
Device varianceexecution cost differs enormously between devices
Code splittingloading only what the current route needs
Tree shakingremoving unused exports at build time
Long tasksanything over 50 milliseconds blocks interaction

Knowing when to hand it over

Tip: Bring in help when bundle size has grown beyond explanation, when INP is failing due to script execution, or when a framework choice is the constraint.

Where this comes from

The figures and practices above come from the sources listed.

Working on something like this?

We take on Performance & Accessibility work for teams who want it done once, properly. Tell us what you are building and we will tell you honestly whether we are the right studio for it. Start a project.

Where to go next

Spotted something wrong? Report an error on this page. We correct on the page and say what changed.

All services

The work behind this article, and what it costs.

Marcus Adeyemi

Builds and maintains the web work. Writes about front-end architecture, performance, accessibility and the unglamorous parts of keeping a site alive.

Keep reading

More in Performance & Accessibility