What is the purpose of the Metadata API in Next.js static metadata?
The Metadata API in Next.js allows you to define page metadata like title, description, and icons statically. This helps improve SEO and user experience by providing consistent information for each page.
Click to reveal answer
beginner
How do you define static metadata in a Next.js page?
You export a constant named metadata from your page file. This object includes properties like title, description, and icons that Next.js uses to generate the HTML metadata tags.
Click to reveal answer
intermediate
Which metadata properties can you set using Next.js static Metadata API?
Common properties include title, description, icons, openGraph for social sharing, and robots for search engine instructions.
Click to reveal answer
beginner
True or False: Static metadata in Next.js can be dynamic and change on the client side.
False. Static metadata is defined at build time and does not change on the client side. For dynamic metadata, you need to use server components or client-side logic.
Click to reveal answer
intermediate
What is the benefit of using static metadata over manually adding <head> tags in Next.js?
Using static metadata is simpler, less error-prone, and integrates with Next.js features like automatic SEO optimization and social sharing previews. It also keeps metadata close to the page code for easier maintenance.
Click to reveal answer
How do you export static metadata in a Next.js page?
AExport a constant named metadata
BUse a function named getMetadata()
CAdd meta tags inside the component JSX
DUse a JSON file named metadata.json
✗ Incorrect
Static metadata is exported as a constant named metadata from the page file.
Which property sets the page title in Next.js static metadata?
ApageTitle
Bheader
Ctitle
Dname
✗ Incorrect
The title property sets the page title in the metadata object.
Can static metadata in Next.js include Open Graph data for social sharing?
ANo
BYes
COnly with plugins
DOnly on client side
✗ Incorrect
Static metadata supports openGraph property to define social sharing info.
When is static metadata processed in Next.js?
AAt build time
BOn every client request
CWhen user clicks a button
DAfter page load
✗ Incorrect
Static metadata is processed at build time and included in the generated HTML.
What is a key advantage of using Next.js Metadata API over manual head tags?
AIt only works on mobile
BIt requires no coding
CIt disables metadata
DIt automatically optimizes SEO and social previews
✗ Incorrect
Next.js Metadata API helps automatically optimize SEO and social sharing previews.
Explain how to add static metadata to a Next.js page and why it is useful.
Think about what metadata does for a webpage and how Next.js uses it.
You got /4 concepts.
List some common properties you can set in Next.js static metadata and their purpose.
Consider what information browsers and search engines need about a page.
You got /5 concepts.
Practice
(1/5)
1. What is the primary purpose of exporting a metadata object in a Next.js page or layout?
easy
A. To provide static information like title and description for SEO and social sharing
B. To define dynamic routes for the page
C. To handle user authentication on the page
D. To style the page with CSS variables
Solution
Step 1: Understand the role of metadata in Next.js
The metadata object is used to add static information such as page title and description.
Step 2: Connect metadata to SEO and social sharing
This information helps search engines and social media platforms display the page correctly.
Final Answer:
To provide static information like title and description for SEO and social sharing -> Option A
Quick Check:
Metadata = SEO info [OK]
Hint: Metadata sets page info for SEO and sharing [OK]
Common Mistakes:
Confusing metadata with routing or styling
Thinking metadata handles user login
Assuming metadata is dynamic by default
2. Which of the following is the correct way to export static metadata in a Next.js page?
easy
A. export default { metadata: { title: 'Home' } }
B. export function metadata() { return { title: 'Home' } }
C. export const metadata = { title: 'Home' }
D. const metadata = { title: 'Home' }; export metadata
Solution
Step 1: Recall the syntax for static metadata export
Next.js expects a named export called metadata as an object.
Step 2: Check each option's syntax
export const metadata = { title: 'Home' } correctly exports a constant object named metadata. The other options use incorrect export forms or syntax.
The description value is written without quotes, which is invalid for strings in JavaScript.
Step 2: Understand JavaScript string syntax
Strings must be enclosed in quotes (' or ") to be valid. Missing quotes cause a syntax error.
Final Answer:
Missing quotes around the description string -> Option B
Quick Check:
Strings need quotes [OK]
Hint: Always quote string values in metadata [OK]
Common Mistakes:
Forgetting quotes around strings
Thinking metadata must be a function
Misplacing export keyword
5. You want to add static metadata with a title, description, and open graph image to a Next.js layout. Which is the correct way to include all these in the metadata export?