Stephen Cooper
A Practical Guide to Reducing Bundle Size
#1about 3 minutes
Why bundle size is important for user experience
Reducing bundle size leads to faster load times and a better user experience, which can also improve SEO rankings through better web vitals.
#2about 1 minute
Understanding tree shaking and dead code elimination
Tree shaking is a form of dead code elimination that removes unused code from the final bundle by analyzing the application's import graph.
#3about 4 minutes
Managing side effects to enable tree shaking
Bundlers avoid removing code with potential side effects, but you can use the `sideEffects: false` property in `package.json` to signal that unused imports are safe to drop.
#4about 2 minutes
Using pure annotations for advanced tree shaking
The `/*#__PURE__*/` annotation tells the bundler that a function call is side-effect-free, allowing it to be removed if its return value is unused.
#5about 3 minutes
How decorators and static properties break tree shaking
Code patterns like decorators and static class properties can create top-level references that prevent bundlers from identifying and removing unused code.
#6about 1 minute
Avoiding barrel files to improve tree shaking
Re-exporting modules from a single "barrel" file (`index.js`) can prevent tree shaking because it forces the bundler to evaluate all exports.
#7about 2 minutes
The importance of testing your bundle size
Small code changes can unexpectedly break tree shaking, so it's crucial to continuously test bundle size using tools like `size-limit` in your CI/CD pipeline.
#8about 1 minute
Debugging bundle size with source map explorer
When tests fail, tools like `source-map-explorer` and `sonder` help visualize the contents of your bundle to identify what code is being incorrectly included.
#9about 2 minutes
How class properties can prevent minification
Minifiers cannot shorten public or TypeScript-private class property names because they could be accessed externally, preserving their full string length in the bundle.
#10about 2 minutes
Using native private fields for better minification
Using native JavaScript private fields (with `#`) allows minifiers to safely mangle property names, but requires targeting modern ES versions to avoid polyfills.
#11about 4 minutes
Advanced patterns for optimizing minification
Further reduce bundle size by replacing verbose error messages with codes, passing class properties as function arguments, and inlining temporary variables.
#12about 1 minute
Comparing build tools and compression methods
The choice of build tool involves a trade-off between build speed and final bundle size, and selecting a modern compression algorithm like Brotli can provide additional savings.
Related jobs
Jobs that call for the skills explored in this talk.
Matching moments
07:02 MIN
Reducing bundle size by replacing heavy dependencies
Challenges of building React and React Native apps
38:47 MIN
How production builds remain highly optimized
The Eternal Sunshine of the Zero Build Pipeline
12:57 MIN
How bundling reveals ESM's performance advantage
Oh CommonJS! Why are you mESMing with me?
22:32 MIN
Reducing JavaScript's impact with smaller bundles
Sustainable me. A tale of good design.
27:17 MIN
The key takeaway is to ship less JavaScript
The Lean Web
09:24 MIN
Why large JavaScript bundles are bad for users and the planet
How Your Bundle Size Affects The Climate
14:54 MIN
Proactive testing with dev tools and bundle analyzers
Frontend Performance Testing in practice
15:20 MIN
Executing JavaScript and optimizing the bundle
The Journey of a Pixel in a React Application
Featured Partners
Related Videos
Tree Shaking the Bytes Away
Francesco Novy
How Your Bundle Size Affects The Climate
Roy Derks
The Eternal Sunshine of the Zero Build Pipeline
M4dz
The Lean Web
Chris Ferdinandi
10 must-know design patterns for JS Devs
Erick Wendel
The Dependency Cookbook - Recipes for Micro Frontend success
Lucas Braeschke & Stefan Bley
Angular tips/tricks you can use from tomorrow on
Benedikt Starzengruber
Native Federation: The Future of Micro Frontends and Plugin-Systems in Angular
Manfred Steyer
From learning to earning
Jobs that call for the skills explored in this talk.

Senior Java Developer
Picnic Technologies B.V.
Amsterdam, Netherlands
Senior
Java
Spring
Amazon Web Services (AWS)

Senior Fullstack Engineer – Angular/.Net (f/m/d)
Apaleo
München, Germany
Remote
€65-85K
Senior
.NET
Angular
JavaScript
+1

Full Stack Engineer
Climax.eco
Rotterdam, Netherlands
€70-100K
Senior
TypeScript
PostgreSQL
Cloud (AWS/Google/Azure)

![Senior Software Engineer [TypeScript] (Prisma Postgres)](https://wearedevelopers.imgix.net/company/283ba9dbbab3649de02b9b49e6284fd9/cover/oKWz2s90Z218LE8pFthP.png?w=400&ar=3.55&fit=crop&crop=entropy&auto=compress,format)
Senior Software Engineer [TypeScript] (Prisma Postgres)
Prisma
Remote
Senior
Node.js
TypeScript
PostgreSQL

Cloud Engineer (m/w/d)
fulfillmenttools
Köln, Germany
€50-65K
Intermediate
TypeScript
Google Cloud Platform
Continuous Integration

Backend Engineer (m/w/d)
fulfillmenttools
Köln, Germany
€35-65K
Intermediate
TypeScript
Agile Methodologies
Google Cloud Platform


Principal Backend Engineer (Node.js)
Almedia
Berlin, Germany
€80-110K
Senior
NestJS
Node.js
Express
TypeScript
+1