How to Fix "Reduce Unused JavaScript" in Next.js & React
To eliminate unused JavaScript in Next.js App Router, keep marketing, documentation, and landing pages as Server Components by default—moving only small interactive widgets into 'use client' leaves—and dynamically import heavy charts or editors.
Why Does This Issue Occur? (Symptom & Cause Matrix)
| Observed Symptom | Root Technical Cause | Recommended Fix |
|---|---|---|
| Entire blog/guide marked 'use client' | Unnecessary client hydration bundle | Keep page.tsx as a Server Component; isolate interactive buttons |
| Heavy chart/markdown libs loaded upfront | Static imports bundled into First Load JS | Use next/dynamic with { ssr: false } for dashboard-only widgets |
Step-by-Step Fix Checklist
- 1
Keep SEO Pages Pure Server Components
Server Components ship zero React component JS to the browser while pre-rendering full HTML + metadata.
- 2
Code-Split Heavy Client Widgets
Wrap admin charts or tables in dynamic(() => import(...)) so marketing visitors never download console JS.
- 3
Load Analytics via afterInteractive
Use Next.js <Script strategy="afterInteractive" /> for telemetry scripts.
Dynamic Import Splitting in Next.js
import dynamic from "next/dynamic";
const HeavyChart = dynamic(() => import("@/components/HeavyChart"), { ssr: false });People Also Ask About This Error
What is a healthy First Load JS size for Next.js SEO pages?
Under 110 kB–130 kB shared First Load JS keeps PageSpeed Insights scores above 95–100/100 on mobile.
Does Server Component rendering help SEO crawling too?
Yes—Googlebot receives complete HTML with headings, links, and schema immediately without waiting for client execution.