
Bundle Size Optimization
- 505 installs
- 305 repo stars
- Updated March 4, 2026
- aj-geddes/useful-ai-prompts
bundle-size-optimization is a Claude Code skill that guides developers through code splitting, tree shaking, and bundle analysis to shrink JavaScript and CSS payloads for faster web app load times.
About
bundle-size-optimization is a skill from aj-geddes/useful-ai-prompts that systematizes JavaScript and CSS bundle reduction through code splitting, tree shaking, and build-time optimization techniques. It applies during build process tuning, bundle analysis before deployment, and performance baseline improvements when downloads, parse time, or execution time regress. Developers reach for it when Lighthouse or webpack/vite reports show oversized chunks or slow first loads, especially on slower networks. The skill includes quick-start steps, reference guides, and best-practice checklists rather than a single framework lock-in. Use it when shipping frontend changes that must meet performance budgets.
- Reduces bundle sizes through code splitting and tree shaking
- Analyzes composition with webpack-bundle-analyzer, Source Map Explorer, Bundle Buddy, and Bundlephobia
- Provides concrete metrics and component-level breakdown
- Targets performance improvements especially for mobile and slower networks
- Applies after adding new dependencies or before deployment
Bundle Size Optimization by the numbers
- 505 all-time installs (skills.sh)
- Ranked #621 of 2,245 Frontend Development skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill bundle-size-optimizationAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 505 |
|---|---|
| repo stars | ★ 305 |
| Last updated | March 4, 2026 |
| Repository | aj-geddes/useful-ai-prompts ↗ |
How do you reduce JavaScript bundle size before deploy?
Systematically reduce JavaScript and CSS bundle sizes for faster load times and better application performance.
Who is it for?
Frontend developers optimizing webpack or vite bundles before deployment to meet performance budgets.
Skip if: Backend-only services or apps already meeting bundle budgets without frontend build tooling.
When should I use this skill?
User mentions large bundles, slow page loads, tree shaking, code splitting, or pre-deploy bundle analysis
What you get
Smaller JS and CSS bundles, split chunk maps, and documented performance optimization changes
- Optimized bundle configuration
- Smaller JS/CSS artifacts
- Performance improvement checklist
Files
Bundle Size Optimization
Table of Contents
Overview
Smaller bundles download faster, parse faster, and execute faster, dramatically improving perceived performance especially on slower networks.
When to Use
- Build process optimization
- Bundle analysis before deployment
- Performance baseline improvement
- Mobile performance focus
- After adding new dependencies
Quick Start
Minimal working example:
// Analyze bundle composition
class BundleAnalysis {
analyzeBundle() {
return {
tools: [
"webpack-bundle-analyzer",
"Source Map Explorer",
"Bundle Buddy",
"Bundlephobia",
],
metrics: {
total_size: "850KB gzipped",
main_js: "450KB",
main_css: "120KB",
vendor: "250KB",
largest_lib: "moment.js (67KB)",
},
breakdown: {
react: "85KB (10%)",
lodash: "45KB (5%)",
moment: "67KB (8%)",
other: "653KB (77%)",
},
};
// ... (see reference guides for full implementation)Reference Guides
Detailed implementations in the references/ directory:
| Guide | Contents |
|---|---|
| Bundle Analysis | Bundle Analysis |
| Optimization Techniques | Optimization Techniques |
| Implementation Strategy | Implementation Strategy |
| Best Practices | Best Practices |
Best Practices
✅ DO
- Follow established patterns and conventions
- Write clean, maintainable code
- Add appropriate documentation
- Test thoroughly before deploying
❌ DON'T
- Skip testing or validation
- Ignore error handling
- Hard-code configuration values
Best Practices
Best Practices
- Monitor bundle size regularly (every build)
- Set strict bundle budgets for teams
- Use modern syntax (don't polyfill all browsers)
- Prefer lighter alternatives to heavy libraries
- Lazy load non-critical code
- Keep vendors separate for better caching
- Remove unused dependencies (npm audit)
- Use production build for measurements
- Test on real 3G network simulation
Bundle Analysis
Bundle Analysis
// Analyze bundle composition
class BundleAnalysis {
analyzeBundle() {
return {
tools: [
"webpack-bundle-analyzer",
"Source Map Explorer",
"Bundle Buddy",
"Bundlephobia",
],
metrics: {
total_size: "850KB gzipped",
main_js: "450KB",
main_css: "120KB",
vendor: "250KB",
largest_lib: "moment.js (67KB)",
},
breakdown: {
react: "85KB (10%)",
lodash: "45KB (5%)",
moment: "67KB (8%)",
other: "653KB (77%)",
},
};
}
identifyOpportunities(bundle) {
const opportunities = [];
// Check for duplicate dependencies
if (bundle.duplicates.length > 0) {
opportunities.push({
issue: "Duplicate dependencies",
impact: "50KB reduction possible",
solution: "Deduplicate packages",
});
}
// Check for unused packages
if (bundle.unused.length > 0) {
opportunities.push({
issue: "Unused dependencies",
impact: "100KB reduction",
solution: "Remove unused packages",
});
}
// Check bundle size vs targets
if (bundle.gzipped > 250) {
opportunities.push({
issue: "Bundle too large",
impact: "Exceeds target",
solution: "Code splitting or tree shaking",
});
}
return opportunities;
}
}Implementation Strategy
Implementation Strategy
Optimization Plan:
Week 1: Analysis & Quick Wins
- Run bundle analyzer
- Remove unused dependencies
- Update large libraries
- Enable tree shaking
- Expected: 20% reduction
Week 2: Code Splitting
- Implement route-based splitting
- Lazy load heavy components
- Split vendor bundles
- Expected: 40% reduction from initial
Week 3: Advanced Optimization
- Remove unused polyfills
- Upgrade transpiler
- Optimize images in bundle
- Expected: 50-60% total reduction
---
Monitoring:
Setup Budget:
- Track bundle size in CI/CD
- Alert if exceeds threshold
- Track per commit
- Historical trending
Tools:
- bundlesize npm package
- webpack-bundle-analyzer
- GitHub checks integration
Process:
- Measure before
- Implement changes
- Measure after
- Document findingsOptimization Techniques
Optimization Techniques
Code Splitting:
Route-based: Split by route (each route ~50-100KB)
Component-based: Split large components
Library splitting: Separate vendor bundles
Tools: webpack, dynamic imports, React.lazy()
Tree Shaking:
Remove unused exports
Enable in webpack/rollup
Works best with ES modules
Check: bundle-analyzer shows unused
Minification:
JavaScript: Terser, esbuild
CSS: cssnano, clean-css
Results: 20-30% reduction typical
Examples: 100KB → 70KB
Remove Dependencies:
Moment.js (67KB) → date-fns (13KB)
Lodash (70KB) → lodash-es (30KB, can tree-shake)
Old packages check: npm outdated
Dynamic Imports:
import('module') loads on-demand
Reduces initial bundle
Used for: Modals, off-screen features
Example: 850KB → 400KB initial + lazy
---
Bundle Size Targets:
JavaScript:
Initial: <150KB gzipped
Per route: <50KB gzipped
Total: <300KB gzipped
CSS:
Initial: <50KB gzipped
Per page: <20KB gzipped
Images:
Total: <500KB optimized
Per image: <100KB// Component: [Name]
// TODO: Customize for your framework (React, Vue, Svelte, etc.)
import React from 'react';
interface Props {
// TODO: Define props
}
export function ComponentName({ }: Props) {
// TODO: Add state and effects
return (
<div>
{/* TODO: Add component markup */}
</div>
);
}
Related skills
FAQ
What techniques does bundle-size-optimization cover?
bundle-size-optimization covers code splitting, tree shaking, and build-time optimization for JavaScript and CSS bundles. The skill targets smaller downloads, faster parse times, and improved load performance before deployment.
When should I use bundle-size-optimization?
Use bundle-size-optimization during build tuning, bundle analysis before deploy, or performance baseline work when JavaScript or CSS payloads grow and page load times regress on production-bound frontend apps.