🚀 SEO, Performance और Deploy · Lesson 29
Performance और Core Web Vitals
Core Web Vitals आसान भाषा में
| Metric | किस सवाल का जवाब | Good | मुख्य Next.js fix |
|---|---|---|---|
| LCP – Largest Contentful Paint | Main content कितनी जल्दी दिखता है? | < 2.5 s | Static pages, priority hero image |
| INP – Interaction to Next Paint | Tap पर page कितनी जल्दी react करता है? | < 200 ms | कम client JS, छोटे Client Components |
| CLS – Cumulative Layout Shift | Load होते समय content उछलता है? | < 0.1 | Images पर width/height, next/font |
कैसे measure करें
- 1npm run build && npm run start (dev mode कभी measure न करें)
- 2Chrome DevTools → Lighthouse → Mobile → Analyze
- 3Live URL के लिए pagespeed.web.dev (traffic के बाद real-user data)
- 4Search Console → Core Web Vitals report
1. Static rendering चुनें
Static (○/●) page milliseconds में cache से serve होता है। Layouts में cookies()/headers() से बचें; कभी-कभी बदलने वाले content के लिए SSR की जगह ISR (revalidate) use करें।
2. Images और fonts
- हर जगह
<Image>, सहीsizes,priorityसिर्फ़ hero पर। display: 'swap'के साथnext/font; 1–2 font families, कम weights।- Source images compress करें (EduSite course images 1200×675 PNG हैं; Next.js WebP serve करता है)।
3. कम JavaScript भेजें
JSX – client islands छोटे रखें
// ❌ whole page becomes client JS
'use client'
export default function CoursePage() { /* big page + one Like button */ }
// ✅ page stays on the server, only the button ships JS
export default function CoursePage() {
return (<>
<BigServerContent />
<LikeButton /> {/* 'use client' inside this small file */}
</>)
}Terminal – bundle analyzer
# See which packages make your JavaScript big (Turbopack bundle analyzer) npx next experimental-analyze # Then open the printed local URL and look for large modules
4. भारी components lazy-load
JSX – next/dynamic
// app/courses/[slug]/page.jsx
import dynamic from 'next/dynamic'
// The chart library (≈ 200 KB) loads only when this component is rendered
const FeeChart = dynamic(() => import('@/components/FeeChart'), {
loading: () => <p>Loading chart…</p>,
})
// In a Client Component you can also skip server rendering:
// const Map = dynamic(() => import('./Map'), { ssr: false })5. next/script से third-party scripts
JSX – next/script strategies
// app/layout.jsx
import Script from 'next/script'
<Script src="https://www.googletagmanager.com/gtag/js?id=G-XXXX" strategy="afterInteractive" />
<Script id="ga" strategy="afterInteractive">
{`window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date()); gtag('config', 'G-XXXX');`}
</Script>
// Chat widget that is not urgent:
<Script src="https://widget.example.com/chat.js" strategy="lazyOnload" />beforeInteractive
- Page block करता है
- सिर्फ़ critical scripts (consent)
- बहुत कम ज़रूरत
afterInteractive / lazyOnload
- Page usable होने के बाद load
- Analytics, ads, chat
- LCP और INP बचाता है
6. तेज़ data
- Independent queries के लिए
Promise.all; WHERE वाले columns पर database indexes। revalidate/ tags से cache; slow हिस्सों को<Suspense>से stream करें।- Server users के पास host करें (India के लिए Mumbai region)।
Launch से पहले checklist
- 1Lighthouse mobile: Performance ≥ 90, SEO 100, Accessibility ≥ 95
- 2Console errors नहीं; images/fonts के 404 नहीं
- 3सारी images next/image से alt text के साथ
- 4Analytics next/script afterInteractive से
- 5Build output: content pages ○/● हों, ƒ नहीं

आम गलतियाँ
- Dev mode में measure करना → numbers का कोई मतलब नहीं।
- छोटे काम के लिए बड़ी libraries (एक date के लिए moment.js) →
Intl.DateTimeFormatuse करें। - Mobile पर auto-play hero videos → LCP खत्म; poster image use करें।
सारांश
- LCP, INP, CLS वे तीन numbers हैं जो Google use करता है।
- Static rendering + next/image + next/font ज़्यादातर problems हल करते हैं।
- छोटे client islands,
next/dynamic,next/scriptJavaScript कम रखते हैं।
✅ Practice
Production build पर Lighthouse (mobile) चलाइए, तीनों metrics लिखिए, इस lesson के दो fixes लगाइए और फिर measure कीजिए।
अक्सर पूछे जाने वाले प्रश्न (FAQ)
npm run dev में Lighthouse score कम क्यों है?
Development mode optimized नहीं होता। हमेशा npm run build और npm run start से, या deployed site पर test करें।
अच्छा LCP कितना है?
Mobile पर 2.5 seconds से कम अच्छा है। Optimized hero image वाले Next.js static pages आमतौर पर 1.5 seconds से कम पहुँच जाते हैं।
क्या Google Analytics Next.js को धीमा करता है?
जल्दी load हो तो कर सकता है। इसे next/script strategy="afterInteractive" या lazyOnload से load करें ताकि page block न हो।
