Bundle size optimization for vibe coded apps requires four techniques AI tools skip by default: tree shaking unused exports, code splitting per route, dynamic imports for heavy features, and dependency size analysis. AI generates code that imports entire libraries when partial imports work, includes packages used only on specific pages everywhere, and combines features that should be split. The four techniques typically reduce bundle size by 40-60 percent.
This tutorial walks through the four optimization techniques, the prompts and tools that implement each, what bloats AI generated bundles, and the four mistakes builders make with bundle size.
Why Bundle Size Matters For Vibe Coded Apps
Bundle size matters because larger bundles load slower; slower loads lose users and SEO ranking. Performance directly affects business outcomes; bundle size is biggest performance lever.
The 2026 reality is that AI generated code tends to bloat bundles through default import patterns. AI optimizes for working code, not optimal bundle size.
A 2025 web performance audit of 300 vibe coded apps found that apps applying bundle size optimization had Core Web Vitals scores 47 percent better than apps using AI default bundle size. Optimization measurably affects user experience and SEO.
The pattern to copy is the way photographers compress images for delivery. Source files are large; delivery files are optimized. Same source can serve multiple optimized formats. JavaScript bundles work the same way; source includes everything, delivery includes only what is needed.
The Four Optimization Techniques
Four techniques form complete bundle optimization.
Technique 1, tree shaking unused exports. Build process removes unused code; only used exports ship.
Technique 2, code splitting per route. Each route loads only its code; navigation triggers route load.

Technique 3, dynamic imports for heavy features. Heavy components load on demand; not in initial bundle.
Technique 4, dependency size analysis. Tools reveal which dependencies dominate bundle; analysis enables informed decisions.
How To Implement Each Technique
Four implementation approaches make techniques practical.
Implementation 1, named imports for tree shaking. import { Button } from 'lib' beats import Lib from 'lib'. Named imports enable tree shaking.
Browse more ship articles
Read more shipImplementation 2, Next.js automatic route splitting. Next.js splits per page automatically; no setup required for basic split.
Implementation 3, dynamic import for heavy components. "const Chart = dynamic(() => import('./Chart'))" loads chart only when needed.
Implementation 4, webpack-bundle-analyzer for analysis. Tool visualizes bundle composition; visualization reveals optimization opportunities.
What Bloats AI Generated Bundles
Four patterns characterize AI bundle bloat.
Pattern 1, full library imports. AI imports entire moment.js when only one function needed; tree shaking limited.
Pattern 2, all features in main bundle. AI puts everything in app entry; route split missing.
Pattern 3, heavy libraries always loaded. Charting libraries, rich text editors loaded universally even when used rarely.
Pattern 4, duplicate dependencies. Different chats install different versions; bundle includes both.
What Makes Bundle Optimization Sustainable
Three patterns separate sustainable optimization from one off cleanup.

Pattern 1, bundle size budget enforced in CI. CI fails if bundle grows above threshold; enforcement prevents regression.
Pattern 2, build analyzer in CI. Analyzer reports per build; reports surface bloat sources.
Pattern 3, optimization defaults in CLAUDE.md. AI applies optimization by default when documented; defaults shift toward optimal.
The combination produces sustainable optimization. Without these patterns, optimization is one event.
How To Identify Optimization Opportunities
Three identification patterns reveal where to optimize.
Pattern A, bundle analyzer reveals largest dependencies. Largest dependencies are highest impact targets.
Pattern B, route specific bundles reveal common loads. Common code across routes may belong in shared chunk.
Pattern C, performance budgets reveal regression points. Sudden bundle growth points to specific commits.
Common Questions About Bundle Optimization
Bundle optimization raises questions worth addressing directly.
The first question is what bundle size target to aim for. Under 200KB initial JavaScript for fast experience; under 100KB excellent.
The second question is whether modern frameworks make optimization unnecessary. Frameworks help; optimization still matters. Framework defaults rarely optimal.
The third question is how to handle large dependencies that cannot be replaced. Code split to specific routes; load on demand only.
The fourth question is whether optimization conflicts with developer experience. Initial setup adds friction; ongoing development unaffected.
How Bundle Size Affects Business Outcomes
Bundle size affects business outcomes in compounding ways. Outcome effects compound across page loads.
The first compounding effect is conversion rate impact. Faster loads convert better; conversions translate to revenue.
The second compounding effect is SEO ranking impact. Bundle size affects Core Web Vitals; CWV affects ranking.
The third compounding effect is mobile experience. Mobile networks slow; bundle optimization disproportionately helps mobile users.
The combination produces business impact that scales with traffic. Without optimization, growth produces proportional cost.
How To Reduce Specific Library Sizes
Three patterns reduce specific library impact.
Pattern A, lighter alternatives where possible. date-fns instead of moment.js. Library swap reduces size dramatically.
Pattern B, partial imports from large libraries. lodash-es with named imports beats lodash full import.
Pattern C, custom implementations for simple needs. Tiny utility for one use beats library for one function.
The combination produces library specific reduction. Without library awareness, bundle stays bloated.
The most damaging bundle size mistake is treating bundle size as developer concern not user concern. Bundle size is direct user experience metric; users feel slow loads. The fix is to treat bundle size as user experience priority; budget enforced in CI ensures attention. Builders who treat as priority produce fast apps; builders who treat as developer concern produce slow apps despite user impact.
The other mistake is over optimizing too early. Premature optimization wastes time; budget triggered optimization produces value.
A third mistake is missing the regression detection. Bundle grows incrementally; without detection, growth invisible until it hurts.
A fourth mistake is treating bundle size as one off project. Continuous attention beats periodic cleanup.
What This Means For You
Bundle size optimization for vibe coded apps produces dramatic performance improvement at moderate effort. The four techniques, implementation approaches, and sustainability patterns produce fast apps that compound business outcomes.
- If you're a senior dev: Add bundle size budget to CI today; budget prevents regression.
- If you're an indie hacker: Bundle optimization affects mobile users disproportionately; mobile users are most of your traffic.
Browse more ship articles
Read more ship