Easy Svelte Optimize
A command template for svelte workflows. Streamlines development with pre-configured patterns and best practices.
Easy Svelte Optimize
Optimize Svelte and SvelteKit applications for performance with bundle analysis, rendering profiling, lazy loading implementation, and build configuration tuning.
When to Use This Command
Run this command when...
- Your Svelte application loads slowly and you need to identify and fix the largest performance bottlenecks across bundle size, rendering, and network requests
- You want to implement lazy loading, code splitting, or image optimization in your SvelteKit application with correct framework patterns
- Your build output is larger than expected and you need to analyze the bundle composition and eliminate dead code or heavy dependencies
Do NOT use this command when...
- Your application has no measurable performance problems -- premature optimization adds complexity without benefit
- You need runtime profiling of server-side Node.js code rather than client-side Svelte rendering
Quick Start
# .claude/commands/easy-svelte-optimize.md # Optimize Svelte performance Optimize: $ARGUMENTS
# Run the command claude "easy-svelte-optimize reduce initial bundle size and implement route-based code splitting"
Expected output:
- Bundle analysis with size breakdown by module
- Top 5 optimization recommendations ranked by impact
- Code splitting implementation for routes
- Lazy loading patterns for heavy components
- Before/after size comparison estimates
Core Concepts
| Concept | Description |
|---|---|
| Bundle Analysis | Visualizing JavaScript bundle composition to identify oversized dependencies |
| Code Splitting | Breaking the application into chunks loaded on demand per route or feature |
| Tree Shaking | Eliminating unused exports from the final bundle during build |
| Rendering Optimization | Reducing unnecessary component re-renders with keyed each blocks and tick batching |
| Preloading Strategy | Configuring SvelteKit preload to fetch data and code before navigation |
Optimization Pipeline:
Current Application
|
[Analyze Bundle]
|
+----+----+----+----+
| | | | |
Size Render Load Build Assets
| | | | |
[Rank by Impact]
|
[Apply Fixes]
|
[Measure Improvement]
|
Optimized Application
Configuration
| Parameter | Default | Description |
|---|---|---|
| Analysis Tool | rollup-plugin-visualizer | Bundle analysis visualization plugin |
| Target Metric | Largest Contentful Paint | Primary web vital to optimize for |
| Splitting Strategy | Route-based | Code splitting by route, feature, or component |
| Image Format | WebP + fallback | Target image format for optimization |
| Build Target | Production | Optimization targets production build configuration |
Best Practices
- Measure before optimizing -- run the analysis first to identify actual bottlenecks. The largest dependency or slowest render may not be what you expect
- Target the biggest wins first -- a single 200KB dependency replacement delivers more impact than micro-optimizing ten 5KB utilities
- Use dynamic imports for heavy features -- wrap infrequently-used components like charts, editors, or admin panels in dynamic imports with loading states
- Optimize images aggressively -- use SvelteKit enhanced:img or a CDN with automatic format conversion. Images are often the single largest page weight contributor
- Test on slow connections -- throttle your network to 3G in DevTools to experience what real users on mobile networks encounter
Common Issues
- Bundle size unchanged after tree shaking -- the dependency may not support ES modules. Check if a lighter alternative exists or configure the build to handle CommonJS properly
- Code splitting creates too many chunks -- overly granular splitting increases HTTP requests. Group related features into logical chunks rather than splitting every component
- Performance regression after optimization -- aggressive lazy loading can cause layout shift. Add skeleton screens and explicit dimensions to prevent cumulative layout shift
Reviews
No reviews yet. Be the first to review this template!
Similar Templates
Git Commit Message Generator
Generates well-structured conventional commit messages by analyzing staged changes. Follows Conventional Commits spec with scope detection.
React Component Scaffolder
Scaffolds a complete React component with TypeScript types, Tailwind styles, Storybook stories, and unit tests. Follows project conventions automatically.
CI/CD Pipeline Generator
Generates GitHub Actions workflows for CI/CD including linting, testing, building, and deploying. Detects project stack automatically.