Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is on-demand revalidation in Next.js?
On-demand revalidation lets you update a static page after it's built, without rebuilding the whole site. You ask Next.js to refresh the page data when something changes.
Click to reveal answer
beginner
Which Next.js function is used to trigger on-demand revalidation?
You use the res.revalidate(path) method inside an API route to tell Next.js to update the static page at the given path.
Click to reveal answer
intermediate
Why use on-demand revalidation instead of rebuilding the whole site?
It saves time and resources by updating only the changed pages, so your site stays fast and fresh without full rebuilds.
Click to reveal answer
beginner
What is a common use case for on-demand revalidation?
When content changes in a CMS or database, you can call on-demand revalidation to update the affected pages immediately.
Click to reveal answer
intermediate
How do you secure an API route that triggers on-demand revalidation?
You add a secret token check in the API route to allow only authorized requests to trigger revalidation.
Click to reveal answer
What does res.revalidate('/path') do in Next.js?
ADisables static generation for '/path'
BDeletes the static page at '/path'
CTriggers a rebuild of the entire site
DUpdates the static page at '/path' with fresh data
✗ Incorrect
The res.revalidate('/path') method tells Next.js to regenerate the static page at '/path' with updated data.
Where do you typically call on-demand revalidation in Next.js?
AInside an API route handler
BInside getStaticProps
CInside the _app.js file
DInside the page component's render method
✗ Incorrect
On-demand revalidation is triggered inside an API route handler where you can call res.revalidate().
Which of these is NOT a benefit of on-demand revalidation?
AFaster updates for changed pages
BFull site rebuild on every content change
CReduced server load compared to full rebuilds
DBetter user experience with fresh content
✗ Incorrect
On-demand revalidation avoids full site rebuilds, so option C is not a benefit.
How can you protect your on-demand revalidation API route?
ABy using a secret token check
BBy disabling API routes
CBy calling revalidate only in getStaticProps
DBy using client-side JavaScript only
✗ Incorrect
Adding a secret token check ensures only authorized requests can trigger revalidation.
When is on-demand revalidation most useful?
AWhen you want to rebuild the entire site daily
BWhen you want to disable static generation
CWhen content changes frequently and you want fast updates
DWhen you never update your site content
✗ Incorrect
On-demand revalidation is great for fast updates when content changes often.
Explain how on-demand revalidation works in Next.js and why it is useful.
Think about how you can refresh a page after it is built without rebuilding the whole site.
You got /4 concepts.
Describe how to secure an API route that triggers on-demand revalidation in Next.js.
Consider how to prevent unauthorized users from forcing page updates.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of on-demand revalidation in Next.js?
easy
A. To disable static site generation completely
B. To rebuild the whole site every time a user visits
C. To update specific static pages instantly without rebuilding the entire site
D. To cache pages permanently without updates
Solution
Step 1: Understand static site generation
Static pages are pre-built and served fast but can become outdated.
Step 2: Role of on-demand revalidation
It updates only specific pages instantly without rebuilding the whole site, keeping content fresh.
Final Answer:
To update specific static pages instantly without rebuilding the entire site -> Option C
Quick Check:
On-demand revalidation = update specific pages fast [OK]
Hint: Remember: on-demand means update only what is needed [OK]
Common Mistakes:
Thinking it rebuilds the entire site
Confusing it with disabling static generation
Assuming pages never update
2. Which Next.js API method is used inside an API route to trigger on-demand revalidation?
easy
A. res.reload(path)
B. res.refresh(path)
C. res.update(path)
D. res.revalidate(path)
Solution
Step 1: Identify the method for revalidation
Next.js provides res.revalidate(path) to trigger revalidation of a page.
Step 2: Confirm method usage in API route
This method is called inside an API route handler to update the static page at the given path.
Final Answer:
res.revalidate(path) -> Option D
Quick Check:
API route uses res.revalidate() to update pages [OK]
Hint: Look for 'revalidate' keyword in the method name [OK]
Common Mistakes:
Using non-existent methods like res.refresh()
Confusing with client-side reload methods
Misspelling the method name
3. Given this API route code snippet, what will happen when a POST request with the correct secret is sent?
B. Not returning after res.json() causing possible errors
C. Using GET method instead of POST for revalidation
D. Incorrect path string in res.revalidate()
Solution
Step 1: Check response handling after revalidation
After calling res.revalidate() and sending JSON, the function should return to avoid continuing execution.
Step 2: Identify missing return statement
The code calls res.json() but does not return, which can cause errors or multiple responses.
Final Answer:
Not returning after res.json() causing possible errors -> Option B
Quick Check:
Always return after sending response [OK]
Hint: Return immediately after sending response [OK]
Common Mistakes:
Using GET instead of POST (allowed but not recommended)
Forgetting to return after res.json()
Assuming res.revalidate() rebuilds entire site
5. You want to revalidate multiple pages on-demand after updating content. Which approach correctly triggers revalidation for '/about' and '/contact' in one API route?
hard
A. await res.revalidate('/about'); await res.revalidate('/contact'); res.json({ revalidated: true })
B. await res.revalidate(['/about', '/contact']); res.json({ revalidated: true })
C. res.revalidate('/about', '/contact'); res.json({ revalidated: true })
D. res.revalidate('/about'); res.revalidate('/contact'); res.json({ revalidated: true })
Solution
Step 1: Understand res.revalidate usage
The res.revalidate() method accepts a single path string and returns a promise.
Step 2: Revalidate multiple pages sequentially
To revalidate multiple pages, call await res.revalidate() separately for each path before sending response.