The Challenge
Our client's e-commerce platform was loading in 4+ seconds. Core Web Vitals were failing across the board, hurting both user experience and SEO rankings. Here's how we fixed it.
Optimization Strategy
1. Image Optimization
Images were responsible for 60% of the page weight. We migrated to Next.js Image component with automatic WebP conversion, responsive sizing, and lazy loading.
import Image from "next/image";
<Image
src="/hero.jpg"
alt="Hero"
width={1200}
height={600}
priority
sizes="(max-width: 768px) 100vw, 1200px"
/>2. Code Splitting with Dynamic Imports
We split heavy components like the checkout modal and analytics dashboard into separate chunks that only load when needed.
const CheckoutModal = dynamic(() => import("@/components/CheckoutModal"), {
loading: () => <CheckoutSkeleton />,
ssr: false
});3. Caching Strategy
Implemented stale-while-revalidate caching for API responses and ISR (Incremental Static Regeneration) for category pages that change frequently.
Results
| Metric | Before | After |
|---|---|---|
| LCP | 4.2s | 0.8s |
| FID | 180ms | 45ms |
| CLS | 0.15 | 0.02 |
| Bundle Size | 420KB | 185KB |
Key Takeaways
Performance optimization is about dozens of small improvements that compound. Focus on the biggest offenders first: usually images and unused JavaScript.