Back to BlogEngineering
How We Reduced Our Bundle Size by 40%
Snigo Team6 min readEngineering
< p > Performance matters.Every kilobyte of JavaScript your users download adds to load time, especially on mobile networks.Here's how we cut 170KB from our web app bundle.
< h2 > The Starting Point
< p > Our bundle had grown to 420KB(gzipped) over 18 months of feature development.We set a target of under 300KB.We ended up at 250KB.
< h2 > Step 1: Bundle Analysis
< p > We started with
webpack - bundle - analyzer < /code> to visualize what was taking up space. The results were eye-opening: a date formatting library (68KB), an icon library (45KB), and duplicated utilities across chunks.
Step 2: Tree - Shaking Fixes
< p > Several of our imports prevented proper tree - shaking.Changingimport _ from 'lodash' to import debounce from 'lodash/debounce' saved 72KB alone. We also ensured all our own modules used proper ES module exports.
< h2 > Step 3: Replace Heavy Libraries
< p > We replaced our date library with a custom 3KB formatter that handled our specific use cases.We switched from a full icon library to individually imported SVGs.Combined savings: 95KB.
< h2 > Step 4: Code Splitting
< p > Settings, team management, and the snippet editor are now lazy - loaded.The initial bundle only includes what's needed for the landing experience: the snippet list and Quickfinder.
< h2 > Step 5: Compression
< p > We switched from gzip to Brotli compression, which gave us an additional 15 - 20 % reduction in transfer size for text - heavy assets like our syntax highlighting themes.
< h2 > Results
< ul >
Bundle size: 420KB → 250KB < /strong> (40% reduction)
First Contentful Paint: 1.8s → 1.1s < /strong>
Lighthouse Performance: 72 → 94 < /strong>
< p > The best part ? Users didn't notice any feature changes. The app does exactly the same thing — it just loads faster.