Skip to the page

Images, fonts, scripts and SEO · mid

Metadata, SEO and social previews

Next.js builds <head> tags from a static metadata export or an async generateMetadata in Server Components, plus file conventions for icons, Open Graph images, robots and sitemap; dynamic pages stream metadata, but bots get it in the initial <head>.

The notes

What you must know

  • Static: export const metadata: Metadata = { title, description } in a layout or page. Dynamic: export async function generateMetadata({ params }). Both only in Server Components.
  • Share the page's data request with React.cache(getPost) so generateMetadata and the page fetch once.
  • File conventions: favicon.ico, icon, apple-icon, opengraph-image, twitter-image, robots.ts, sitemap.ts (static by default unless they use request-time APIs). Deeper opengraph-image files override higher ones.
  • Dynamic OG images: opengraph-image.tsx returning new ImageResponse(<div>...</div>) from next/og (flexbox and a CSS subset only, no grid).
  • Streaming metadata: for dynamic pages metadata is injected after generateMetadata resolves without blocking UI; bots like Twitterbot, Slackbot, Bingbot get blocking metadata (configurable with htmlLimitedBots). Prerendered pages resolve metadata at build.
  • SEO basics: canonical URLs and alternates.languages (hreflang), split large sitemaps (generateSitemaps), JSON-LD in a <script type="application/ld+json"> with < escaped.
  • Do not set document.title in effects; client-side titles are invisible to many crawlers and flash.

The red pen

Common traps: mistake → fix

  • Mistake: "generateMetadata works in Client Components"

    Fix: Server Components only.

  • Mistake: "Put user text into JSON-LD with JSON.stringify only"

    Fix: a </script> in the data breaks out; escape <.

  • Mistake: "One sitemap for 40,000 URLs"

    Fix: split into multiple sitemaps.

Easy to hard

Questions interviewers ask, easy to hard

  1. How do you handle SEO in the App Router: titles, canonicals, OG images, sitemaps and robots for 40k product pages?
  2. How do generateMetadata and the page avoid fetching twice?
  3. How do you generate a dynamic OG image?
  4. What is streaming metadata and how do bots see it?
  5. How do you add JSON-LD safely?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview