Performance: Metadata API for SEO
This affects the page load speed and SEO by controlling how metadata is rendered and delivered to browsers and search engines.
import { Metadata } from 'next'; export const metadata: Metadata = { title: 'Static or dynamic title', description: 'Page description for SEO', }; export default function Page() { return <main>Page content</main>; }
export default function Page() { return ( <> <Head> <title>{dynamicTitle}</title> <meta name="description" content={dynamicDescription} /> </Head> <main>Page content</main> </> ) }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Client-side <Head> injection | Adds extra DOM nodes after initial load | Triggers reflow on metadata injection | Increases paint cost due to delayed metadata | [X] Bad |
| Next.js Metadata API server-side | Metadata included in initial DOM | No extra reflows for metadata | Minimal paint cost, metadata ready on first paint | [OK] Good |
metadata export in a Next.js page?metadata export is used to set SEO-related information such as the page title and description.metadata.export const metadata = {...}.export const metadata = {
title: 'About Us - MySite',
description: 'Learn more about us'
}title property is set to 'About Us - MySite'. This is what appears in the browser tab.description is for SEO and social previews, not the browser tab title.const metadata = {
title: 'Contact'
}
export default metadatametadata to be a named export, not a default export.openGraph key with properties like title and images (array of URLs).openGraph object with title and images array.Pass the test and this pattern moves unknown