Dabish Digital
Development

Before you invest in JavaScript bundle size

This is cheap to get right at the start and expensive to retrofit. Before you spend anything on JavaScript bundle size, it is worth confirming a few things are already true.

The question is rarely whether something can be built, but what it costs to keep running afterwards. Check it against what you would want a competitor's site to get wrong.

Prerequisites

  • You can describe the outcome you want in one sentence
  • Someone owns it after the work is done
  • Every kilobyte of JavaScript costs more than a kilobyte of image
  • You have a way to tell whether it worked

Where it usually goes wrong

Most sites ship libraries for features they barely use. That sounds obvious written down. It is still the thing most often skipped. Doing this properly once is usually cheaper than doing it approximately three times.

Measure the bundle before optimising anything else. Getting it slightly wrong is survivable. Ignoring it entirely is not. It is worth deciding this deliberately rather than inheriting whatever the last person set up.

In practice

Code gets read far more often than it gets written, and usually by someone with less context than the author had. Three things worth confirming about JavaScript bundle size before you move on:

  • Someone can say what the current setup is without going to look
  • Most sites ship libraries for features they barely use — and you know whether that is true here
  • There is a way to tell whether the last change to this helped

Pick the one that would hurt most if it failed, and start there.