Metadata API: Dynamic SEO, OpenGraph Tags & Sitemap Generation
Metadata API: Dynamic SEO, OpenGraph Tags & Sitemap Generation
Search Engine Optimization (SEO) and social media link previews are vital for digital reach. Next.js 15 features the built-in Metadata API, allowing developers to define static or dynamic SEO tags, OpenGraph images, Twitter cards, and programmatic sitemaps directly through type-safe TypeScript interfaces.
1. Static Metadata
Define static metadata by exporting a metadata object from any layout.tsx or page.tsx:
2. Dynamic Metadata with generateMetadata()
For dynamic pages (e.g., /courses/[slug]), metadata depends on database content. Export an async generateMetadata() function:
3. Programmatic Sitemaps: sitemap.ts
Search engines discover your entire content catalog through a sitemap.xml. Create app/sitemap.ts to generate dynamic sitemaps automatically:
Next.js automatically serves this at /sitemap.xml!
Multiple Choice Questions
app/ directory automatically generates a standardized sitemap.xml for search engines?layout.tsx versus a child page.tsx?generateMetadata() and the page component need it?Production Optimization, Dockerization & Vercel Cloud Deployment
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Related Lessons
Practice Quiz
Test your understanding of this lesson with 5 questions. Each question has one correct answer.