0
0
NextJSframework~10 mins

Metadata API (static metadata) in NextJS - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Metadata API (static metadata)
Define metadata object
Export metadata
Next.js reads metadata at build
Static metadata applied to page
Browser receives page with metadata
This flow shows how you define and export static metadata in Next.js, which Next.js reads at build time to add metadata to the page.
Execution Sample
NextJS
export const metadata = {
  title: 'Home Page',
  description: 'Welcome to our site',
};

export default function Page() {
  return <h1>Hello</h1>;
}
Defines static metadata for a page and exports a simple React component.
Execution Table
StepActionEvaluationResult
1Read export 'metadata'metadata object found{ title: 'Home Page', description: 'Welcome to our site' }
2Next.js processes metadata at buildStatic metadata recognizedMetadata ready to inject in HTML head
3Render Page componentJSX <h1>Hello</h1>HTML <h1>Hello</h1> rendered
4Inject metadata into HTML headAdd <title> and <meta><title>Home Page</title> and <meta name="description" content="Welcome to our site"> added
5Send final HTML to browserPage with metadata and contentBrowser receives page with title and description
6ExitAll steps completeStatic metadata applied successfully
💡 All metadata processed and page rendered with static metadata
Variable Tracker
VariableStartAfter Step 1After Step 2Final
metadataundefined{ title: 'Home Page', description: 'Welcome to our site' }{ title: 'Home Page', description: 'Welcome to our site' }{ title: 'Home Page', description: 'Welcome to our site' }
Key Moments - 2 Insights
Why does Next.js read the metadata object before rendering the page?
Next.js reads the exported metadata object at build time (see Step 2 in execution_table) to generate static HTML with metadata included, improving SEO and performance.
What happens if the metadata object is missing or empty?
If metadata is missing, Next.js will render the page without static metadata tags (no title or description), so SEO benefits are lost (not shown in execution_table but implied).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the metadata value after Step 1?
A{}
Bundefined
C{ title: 'Home Page', description: 'Welcome to our site' }
Dnull
💡 Hint
Check the 'Result' column in row for Step 1 in execution_table
At which step does Next.js inject the metadata into the HTML head?
AStep 3
BStep 4
CStep 2
DStep 5
💡 Hint
Look for the action mentioning 'Inject metadata into HTML head' in execution_table
If you change the metadata title, which step reflects that change in the execution_table?
AStep 1
BStep 3
CStep 4
DStep 5
💡 Hint
Metadata value is first read and evaluated at Step 1
Concept Snapshot
Next.js static Metadata API:
- Export a 'metadata' object from your page file
- Next.js reads it at build time
- Metadata is injected into HTML head
- Improves SEO and page info
- Works only with static metadata (no runtime changes)
Full Transcript
This visual trace shows how Next.js handles static metadata. First, the metadata object is defined and exported from the page file. Next.js reads this metadata at build time before rendering the page. Then, it injects the metadata into the HTML head, adding the title and description tags. Finally, the page with metadata is sent to the browser. This process ensures metadata is static and improves SEO. If metadata is missing, the page renders without these tags. Changing metadata updates the content at build time only.