The big checklist for a small JavaScript bundle
This is a list of all the things I know, and all the things we’ve used to reduce the bundle size of the Peacock / SkyShowtime / NOW TV app. You’re more than welcome to use this checklist to improve your own projects.
Finally, keep monitoring the size of your JavaScript bundle! Peacock’s CI measures the bundle size change of each PR and adds it as comment during code review. bundle-stats is one cool project that can help with this.
Also, something as simple as:
// src/index.js
export const UNUSED_EXPORT = 'THIS_SHOULD_NOT_BE_BUNDLED';
plus a CI test like:
grep -rq "THIS_SHOULD_NOT_BE_BUNDLED" dist
can go a long way in catching certain regressions.
In fact, now that I write this, I realise that awareness of your bundle size is actually the first step in this long journey. Optimization is an ongoing process, not a one-time task. Good luck!
P. S. – If you enjoyed the hand-drawn checkboxes I explain how to implement them in my post Web Component: Hand-drawn Checkbox.