Core Web Vitals e monitoraggio
Comprenda LCP, INP e CLS, li misuri sugli utenti reali e usi le funzionalità di Next.js e gli strumenti di osservabilità per mantenere veloce l’app in produzione.
Core Web Vitals e monitoraggio è una lezione Next.js 15 Fullstack Web Apps gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Next.js 15 Fullstack Web Apps, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Next.js 15 Fullstack Web Apps include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
What Are Core Web Vitals
Core Web Vitals are Google's user-centric performance metrics that influence both UX and SEO ranking. The three current metrics are:
- LCP — Largest Contentful Paint (loading)
- INP — Interaction to Next Paint (responsiveness)
- CLS — Cumulative Layout Shift (visual stability)
LCP: Loading Speed
LCP measures when the largest visible element (often a hero image or heading) finishes rendering. Aim for under 2.5s. Improve it with image optimization, priority loading, and server rendering.
import Image from 'next/image';
<Image src="/hero.jpg" alt="Hero" width={1200} height={600} priority />INP: Responsiveness
INP replaced FID. It measures the latency of user interactions across the whole visit. Aim for under 200ms. Long JavaScript tasks on the main thread hurt INP most.
CLS: Visual Stability
CLS quantifies unexpected layout shifts. Aim for under 0.1. Always set explicit width and height on images and reserve space for ads and embeds.
Lab vs Field Data
Lab data comes from a controlled run (Lighthouse). Field data (RUM) comes from real users on real devices. Field data is the source of truth for ranking; lab data is great for debugging.
Reporting with useReportWebVitals
Next.js exposes useReportWebVitals to collect real-user metrics and send them to your analytics endpoint.
'use client';
import { useReportWebVitals } from 'next/web-vitals';
export function Vitals() {
useReportWebVitals((metric) => {
navigator.sendBeacon('/api/vitals', JSON.stringify(metric));
});
return null;
}Bucketing a Metric
Classify a metric value into good / needs-improvement / poor. Pure logic you can run anywhere.
function rateLCP(ms) {
if (ms <= 2500) return 'good';
if (ms <= 4000) return 'needs-improvement';
return 'poor';
}
console.log(rateLCP(1800));
console.log(rateLCP(3200));
console.log(rateLCP(5000));Reducing Main-Thread Work
To improve INP, ship less JavaScript and defer non-critical work. Use dynamic imports to code-split heavy client components.
import dynamic from 'next/dynamic';
const Chart = dynamic(() => import('./Chart'), { ssr: false });Server Components Help
React Server Components render on the server and send no JavaScript to the client for that part of the tree, directly reducing bundle size and improving INP and LCP.
Production Monitoring Tools
Set up continuous observability:
- Vercel Speed Insights for built-in RUM.
- Vercel Analytics for traffic.
- Sentry / OpenTelemetry for errors and traces.
Alert when a metric regresses past its threshold.
Set a Performance Budget
Define budgets (e.g. LCP < 2.5s, JS < 170KB) and enforce them in CI so regressions fail the build before they reach users.
Quick Check
Which Core Web Vital measures the responsiveness of user interactions, and what is its target?
Recap
You learned to keep production fast:
- LCP (loading), INP (responsiveness), and CLS (stability) with their targets.
- The difference between lab and field data.
- Collecting RUM with
useReportWebVitals. - Reducing JS via code splitting and Server Components, plus monitoring and budgets.
Domande Frequenti
La lezione «Core Web Vitals e monitoraggio» è gratuita?
Sì — il testo completo di «Core Web Vitals e monitoraggio» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Next.js 15 Fullstack Web Apps, passa a CoddyKit PRO. Il corso Next.js 15 Fullstack Web Apps include 4 lezioni in totale.
Cosa imparerò in «Core Web Vitals e monitoraggio»?
Comprenda LCP, INP e CLS, li misuri sugli utenti reali e usi le funzionalità di Next.js e gli strumenti di osservabilità per mantenere veloce l’app in produzione. Eserciti Next.js 15 Fullstack Web Apps con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare Next.js 15 Fullstack Web Apps?
Non è richiesta alcuna esperienza precedente. Next.js 15 Fullstack Web Apps su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.
Quanto tempo richiede la lezione «Core Web Vitals e monitoraggio»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione Next.js 15 Fullstack Web Apps?
Sì. Ogni lezione Next.js 15 Fullstack Web Apps include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Distribuzione su Vercel e Netlify
- Ottimizzazione di immagini e font
- Analisi del bundle e audit delle prestazioni
- Core Web Vitals e monitoraggio