Performance: Font optimization with next/font
HIGH IMPACT
This affects page load speed by optimizing font delivery and rendering, reducing blocking time and layout shifts.
import { Inter } from 'next/font/google'; const inter = Inter({ subsets: ['latin'], variable: '--font-inter' }); export default function App({ Component, pageProps }) { return <main className={inter.variable}><Component {...pageProps} /></main>; }
import '../styles/globals.css'; // In globals.css @font-face { font-family: 'CustomFont'; src: url('/fonts/customfont.woff2') format('woff2'); font-display: swap; } // Use font-family: 'CustomFont' in CSS
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| CSS @font-face with font-display: swap | Minimal DOM impact | Triggers reflow on font swap | Paint cost on font swap | [!] OK |
| next/font with automatic preload and subset | Minimal DOM impact | Single reflow during initial layout | Reduced paint cost | [OK] Good |