Free tutorials & notes in Hindi & English · Clean code examples 🧰 मुफ़्त PDF और फ़ोटो टूल्स →
🚀 SEO, Performance और Deploy  ·  Lesson 29

Performance और Core Web Vitals

Core Web Vitals आसान भाषा में

Metricकिस सवाल का जवाबGoodमुख्य Next.js fix
LCP – Largest Contentful PaintMain content कितनी जल्दी दिखता है?< 2.5 sStatic pages, priority hero image
INP – Interaction to Next PaintTap पर page कितनी जल्दी react करता है?< 200 msकम client JS, छोटे Client Components
CLS – Cumulative Layout ShiftLoad होते समय content उछलता है?< 0.1Images पर width/height, next/font
RequestTTFBserver जवाबFCPपहला textLCPhero दिखाInteractiveINP
Page load की timeline

कैसे measure करें

  1. 1npm run build && npm run start (dev mode कभी measure न करें)
  2. 2Chrome DevTools → Lighthouse → Mobile → Analyze
  3. 3Live URL के लिए pagespeed.web.dev (traffic के बाद real-user data)
  4. 4Search Console → Core Web Vitals report
Measure करें, एक चीज़ बदलें, फिर measure करें

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 बचाता है
जो सबसे बाद वाली strategy काम करे वही चुनें

6. तेज़ data

  • Independent queries के लिए Promise.all; WHERE वाले columns पर database indexes।
  • revalidate / tags से cache; slow हिस्सों को <Suspense> से stream करें।
  • Server users के पास host करें (India के लिए Mumbai region)।

Launch से पहले checklist

  1. 1Lighthouse mobile: Performance ≥ 90, SEO 100, Accessibility ≥ 95
  2. 2Console errors नहीं; images/fonts के 404 नहीं
  3. 3सारी images next/image से alt text के साथ
  4. 4Analytics next/script afterInteractive से
  5. 5Build output: content pages ○/● हों, ƒ नहीं
EduSite पाँचों pass करता है
EduSite mobile home page
Mobile पर EduSite — static page, optimized hero image, self-hosted font

आम गलतियाँ

  • Dev mode में measure करना → numbers का कोई मतलब नहीं।
  • छोटे काम के लिए बड़ी libraries (एक date के लिए moment.js) → Intl.DateTimeFormat use करें।
  • 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/script JavaScript कम रखते हैं।
✅ 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 न हो।
← Next.js Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

अगला topicNext.js Deploy करें (Vercel, VPS, Static) आपकी प्रगति: 29 / 37 (78%) · Lesson 30 / 37 आगे बढ़ें →

यह lesson कैसा लगा?

आपकी राय से हम content और बेहतर बनाते हैं।

अपना review और सुझाव लिखें (वैकल्पिक)

Review approve होने के बाद आपका नाम और शहर इसके साथ public दिख सकते हैं। Email या phone न लिखें।

▶ CodingEasily on YouTube

Video से सीखें – आसान Hindi में

चुनी हुई video: RDBMS भाग 3 – Class XI Commerce IT

▶ Channel subscribe करें