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>.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe 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)sogenerateMetadataand 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). Deeperopengraph-imagefiles override higher ones. - Dynamic OG images:
opengraph-image.tsxreturningnew ImageResponse(<div>...</div>)fromnext/og(flexbox and a CSS subset only, no grid). - Streaming metadata: for dynamic pages metadata is injected after
generateMetadataresolves without blocking UI; bots like Twitterbot, Slackbot, Bingbot get blocking metadata (configurable withhtmlLimitedBots). 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.titlein effects; client-side titles are invisible to many crawlers and flash.
The red pen
Common traps: mistake → fix
Mistake: "
generateMetadataworks in Client Components"Fix: Server Components only.
Mistake: "Put user text into JSON-LD with
JSON.stringifyonly"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
- How do you handle SEO in the App Router: titles, canonicals, OG images, sitemaps and robots for 40k product pages?
- How do
generateMetadataand the page avoid fetching twice? - How do you generate a dynamic OG image?
- What is streaming metadata and how do bots see it?
- 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 voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.