Analyze and reduce JavaScript bundle size by identifying large dependencies, code splitting opportunities, and tree shaking improvements.
Fill in this template
The {{ }} placeholders are variables — drop in your own details, then copy the ready-to-use prompt. (Or copy the template as-is and let your AI assistant fill them in.)
0/3 filled
Preview filled prompt
You are a frontend performance engineer specializing in bundle optimization.
## Bundle Analysis
{{BUNDLE_ANALYSIS}}
## Framework
{{FRAMEWORK}}
## Dependencies
{{DEPENDENCIES}}
## Bundle Optimization Analysis
### 1. Dependency Audit
For each large dependency in the bundle:
- What is its gzipped size?
- Is the entire package imported or just specific modules?
- Is there a lighter alternative? (e.g., date-fns vs. moment, lodash-es vs. lodash)
- Can it be replaced with native browser APIs?
- Is it a dev dependency that leaked into production?
### 2. Code Splitting Opportunities
- **Route-based splitting**: Are all routes in the main bundle?
- **Component-based splitting**: Are heavy components (charts, editors, maps) lazy-loaded?
- **Feature-based splitting**: Are features behind flags still in the main bundle?
- **Vendor splitting**: Are vendor chunks configured optimally?
### 3. Tree Shaking Analysis
- Are imports using named imports (tree-shakeable) or default/namespace imports?
- Are barrel files (index.ts re-exports) preventing tree shaking?
- Are packages shipping ESM builds for better tree shaking?
- Is the bundler configured to sideEffects: false where appropriate?
### 4. Asset Optimization
- Are images optimized and served in modern formats (WebP, AVIF)?
- Are fonts subsetted to only used characters?
- Are SVGs optimized and possibly inlined?
- Is CSS purged of unused styles?
### 5. Loading Strategy
- Is critical CSS inlined?
- Are scripts using defer or async appropriately?
- Is there a prefetch/preload strategy for likely next navigations?
- Are third-party scripts (analytics, chat) loaded after interaction?
### 6. Framework-Specific Optimizations
Based on {{FRAMEWORK}}:
- React: React.lazy, Suspense boundaries, server components
- Next.js: next/dynamic, Image component, font optimization, RSC
- Vue: defineAsyncComponent, route-level splitting
- Svelte: Dynamic imports, adapter optimizations
## Output Format
1. **Current State**: Total bundle size (raw + gzipped), breakdown by chunk
2. **Top 5 Wins**: Ordered by size reduction potential with estimated savings
3. **Implementation Guide**: Step-by-step instructions for each optimization
4. **Configuration Changes**: Webpack/Vite/Turbopack config updates
5. **Import Rewrites**: Before/after for each import optimization
6. **Performance Budget**: Recommended size limits per chunkTags
performancefrontendbundle-sizeoptimizationjavascript
Explore more prompts and rules
BeforeMerge offers hundreds of AI prompts, code review rules, guides, and detection patterns to help your team ship better code.