Optimizing Core Web Vitals in Heavy Next.js Applications
Practical strategies for scoring 95+ on Google Lighthouse in Next.js applications that heavily utilize Framer Motion and GSAP.
Building highly interactive, animation-heavy marketing sites often comes at the cost of performance. Browsers struggle to parse large JavaScript bundles quickly, leading to poor Largest Contentful Paint (LCP) and Interaction to Next Paint (INP) scores.
Here is how we maintain a premium aesthetic without sacrificing Core Web Vitals.
Dynamic Imports for Heavy Libraries
Instead of importing heavy animation libraries globally, we use Next.js dynamic imports to lazy-load them only when they enter the viewport.
import dynamic from 'next/dynamic'// Only load the massive Three.js model when the user scrolls to it
const Heavy3DScene = dynamic(() => import('./scene'), { ssr: false })
CSS Over JS for Initial Load
We ensure that the initial viewport (above the fold) uses CSS animations or highly optimized inline styles for its initial state, deferring React hydration until after the first paint. This drastically improves the perceived load time.