| 33 | // ─── Core Web Vitals ──────────────────────────────────────────────────────── |
| 34 | |
| 35 | function rateVital(name: string, value: number): PerformanceMetric["rating"] { |
| 36 | const thresholds: Record<string, [number, number]> = { |
| 37 | LCP: [2500, 4000], |
| 38 | FID: [100, 300], |
| 39 | CLS: [0.1, 0.25], |
| 40 | INP: [200, 500], |
| 41 | TTFB: [800, 1800], |
| 42 | FCP: [1800, 3000], |
| 43 | }; |
| 44 | const [good, poor] = thresholds[name] ?? [0, Infinity]; |
| 45 | if (value <= good) return "good"; |
| 46 | if (value <= poor) return "needs-improvement"; |
| 47 | return "poor"; |
| 48 | } |
| 49 | |
| 50 | export function observeWebVitals(): void { |
| 51 | if (typeof window === "undefined" || !("PerformanceObserver" in window)) return; |