Performance FAQ
Questions about optimizing VitePress site performance.
Build Performance
Q: My build is taking too long
A: Optimization strategies:
- Reduce the number of pages
- Optimize images before adding them
- Use dynamic imports for large components
- Enable parallel processing
- Use SSD storage for faster I/O
Q: How can I speed up the development server?
A: Tips for faster dev server:
- Use
--host
flag for network access - Reduce the number of files being watched
- Close unnecessary browser tabs
- Use
--debug
to identify bottlenecks
Runtime Performance
Q: My site loads slowly for users
A: Performance improvements:
- Optimize images: Use WebP format, proper sizing
- Enable compression: Gzip/Brotli on server
- Use CDN: Serve static assets from CDN
- Minimize JavaScript: Remove unused code
- Lazy load content: Load content as needed
Q: How do I optimize images?
A: Image optimization techniques:
javascript
// In .vitepress/config.js
export default {
vite: {
plugins: [
// Add image optimization plugin
]
}
}
- Use appropriate formats (WebP, AVIF)
- Compress images before adding
- Use responsive images with srcset
- Implement lazy loading
Bundle Size
Q: My JavaScript bundle is too large
A: Reduce bundle size:
- Tree shaking: Remove unused code
- Code splitting: Split into smaller chunks
- Dynamic imports: Load components on demand
- Analyze bundle: Use bundle analyzer tools
Q: How do I analyze my bundle size?
A: Use bundle analysis tools:
bash
npm install --save-dev rollup-plugin-visualizer
Add to vite config:
javascript
import { visualizer } from 'rollup-plugin-visualizer'
export default {
vite: {
plugins: [
visualizer({
filename: 'dist/stats.html',
open: true
})
]
}
}
Caching Strategies
Q: How do I implement proper caching?
A: Caching configuration:
- Static assets: Long-term caching with versioning
- HTML files: Short-term caching
- Service worker: For offline functionality
- CDN caching: Edge caching for global users
Q: My updates aren't showing for users
A: Cache busting solutions:
- Check cache headers
- Use versioned asset names
- Implement proper cache invalidation
- Clear CDN cache after deployment
Core Web Vitals
Q: How do I improve Largest Contentful Paint (LCP)?
A: LCP optimization:
- Optimize server response times
- Remove render-blocking resources
- Optimize images and media
- Use preload for critical resources
Q: How do I reduce Cumulative Layout Shift (CLS)?
A: CLS improvements:
- Include size attributes on images
- Reserve space for dynamic content
- Use CSS aspect-ratio property
- Avoid inserting content above existing content
Q: How do I improve First Input Delay (FID)?
A: FID optimization:
- Minimize JavaScript execution time
- Use web workers for heavy computations
- Optimize third-party scripts
- Implement code splitting
Monitoring
Q: How do I monitor my site's performance?
A: Monitoring tools:
- Lighthouse: Built-in Chrome auditing
- PageSpeed Insights: Google's performance tool
- WebPageTest: Detailed performance analysis
- Real User Monitoring: Track actual user experience
Q: What metrics should I track?
A: Key performance metrics:
- Core Web Vitals: LCP, FID, CLS
- Time to First Byte: Server response time
- First Contentful Paint: Initial content rendering
- Speed Index: Visual completeness
- Total Blocking Time: Main thread blocking