Performance: Open Graph and Twitter cards
This affects the page load speed and initial rendering by adding metadata that social platforms use to generate rich previews.
import Head from 'next/head'; export default function Page() { return ( <> <Head> <meta property="og:title" content="My Page" /> <meta property="og:description" content="Description here" /> <meta property="og:image" content="/optimized-image.webp" /> <meta name="twitter:card" content="summary_large_image" /> <meta name="twitter:image" content="/optimized-image.webp" /> </Head> <main>Content</main> </> ); }
import Head from 'next/head'; export default function Page() { return ( <> <Head> <meta property="og:title" content="My Page" /> <meta property="og:description" content="Description here" /> <meta property="og:image" content="/large-image.jpg" /> <meta name="twitter:card" content="summary_large_image" /> <meta name="twitter:image" content="/large-image.jpg" /> </Head> <main>Content</main> </> ); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Large unoptimized OG image | Minimal (metadata only) | 0 | High due to image load delay | [X] Bad |
| Optimized OG image with compressed format | Minimal (metadata only) | 0 | Low paint cost | [OK] Good |
| Metadata with blocking scripts in head | Minimal | 0 | High due to render-blocking | [X] Bad |
| Metadata only, no blocking scripts | Minimal | 0 | Low paint cost | [OK] Good |
Head component improves link previews, not performance or fonts.Head component?property="og:..." attribute, not name.Head usageHead with correct attributes; property="og:title" is correct for Open Graph title.import Head from 'next/head';
export default function Page() {
return (
<Head>
<meta name="twitter:title" content="Welcome to Next.js" />
</Head>
);
}name="twitter:title" which is correct for Twitter cards.Head renders meta tags as written, so the tag will appear exactly as coded.<Head> <meta name="twitter:card" content="summary_large_image" /> <meta name="twitter:image" content="/images/card.png" /> </Head>What is the most likely reason the image does not appear on Twitter?
name="twitter:image" is correct; Twitter supports images in cards.Head component?property="og:..." with absolute image URL, which is correct in options A, C, D.name="twitter:..." and include twitter:card with value summary_large_image for large image preview, correctly done only in A.Pass the test and this pattern moves unknown