0
0
NextJSframework~8 mins

Open Graph and Twitter cards in NextJS - Performance & Optimization

Choose your learning style9 modes available
Performance: Open Graph and Twitter cards
MEDIUM IMPACT
This affects the page load speed and initial rendering by adding metadata that social platforms use to generate rich previews.
Adding social media preview metadata to a Next.js page
NextJS
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>
    </>
  );
}
Using optimized, compressed images in modern formats reduces load time and speeds up LCP.
📈 Performance GainReduces image load time by 50-70%, improving LCP by 150-300ms.
Adding social media preview metadata to a Next.js page
NextJS
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>
    </>
  );
}
Using large images without optimization causes slower page load and delays Largest Contentful Paint (LCP).
📉 Performance CostBlocks rendering for 200-400ms on slow connections due to large image fetch.
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Large unoptimized OG imageMinimal (metadata only)0High due to image load delay[X] Bad
Optimized OG image with compressed formatMinimal (metadata only)0Low paint cost[OK] Good
Metadata with blocking scripts in headMinimal0High due to render-blocking[X] Bad
Metadata only, no blocking scriptsMinimal0Low paint cost[OK] Good
Rendering Pipeline
Open Graph and Twitter card metadata are parsed during the HTML parsing stage and do not trigger layout or paint. However, referenced images can delay the loading of the main content if not optimized.
HTML Parsing
Network Loading
Largest Contentful Paint
⚠️ BottleneckNetwork Loading of large images referenced in metadata
Core Web Vital Affected
LCP
This affects the page load speed and initial rendering by adding metadata that social platforms use to generate rich previews.
Optimization Tips
1Use optimized, compressed images in Open Graph and Twitter card metadata to improve LCP.
2Avoid adding render-blocking scripts or large assets in the head with metadata.
3Keep metadata minimal and only include necessary tags to prevent blocking the critical rendering path.
Performance Quiz - 3 Questions
Test your performance knowledge
How does using large unoptimized images in Open Graph tags affect page performance?
AIt delays Largest Contentful Paint by increasing image load time
BIt improves page load speed by caching images
CIt has no effect on page performance
DIt reduces Cumulative Layout Shift
DevTools: Performance
How to check: Open DevTools, go to Performance tab, record page load, and look for Largest Contentful Paint timing and any long tasks blocking rendering.
What to look for: Check if image loading delays LCP or if scripts block main thread causing delayed paint.