Consider a Next.js page using getStaticProps with revalidate set. When you call res.revalidate('/path') in an API route, what is the immediate effect on the page?
export async function getStaticProps() { return { props: { time: Date.now() }, revalidate: 10 }; } export default function Page({ time }) { return <p>Time: {time}</p>; } // API route handler export default async function handler(req, res) { await res.revalidate('/path'); res.status(200).json({ revalidated: true }); }
Think about how Next.js handles static regeneration and when the new content becomes available.
On-demand revalidation triggers a background rebuild of the page. The updated content is not served until the next request after the rebuild finishes. The current users do not see the update instantly.
Choose the correct way to trigger on-demand revalidation for the path /blog/post-1 inside a Next.js API route.
export default async function handler(req, res) { // Your code here }
Remember to await the revalidation and send a proper HTTP status with JSON response.
The res.revalidate method returns a promise, so it must be awaited. Also, sending a 200 status with JSON is the recommended pattern.
Given this API route code, why does calling it cause a 500 error?
export default async function handler(req, res) { try { await res.revalidate('/'); res.status(200).json({ revalidated: true }); } catch (err) { res.status(500).json({ message: err.message }); } }
Check Next.js docs about securing on-demand revalidation.
Next.js requires a secret token in the query string to authorize on-demand revalidation. Without it, the call fails with 500.
Assume a Next.js page shows the current timestamp from getStaticProps with revalidate: 60. After calling res.revalidate('/time') in an API route, what will the page show on the next request?
export async function getStaticProps() { return { props: { time: Date.now() }, revalidate: 60 }; } export default function TimePage({ time }) { return <p>Timestamp: {time}</p>; }
Think about when the page props update after on-demand revalidation.
On-demand revalidation rebuilds the page immediately in the background. The next request after rebuild gets the updated timestamp.
Choose the correct statement about how on-demand revalidation works in Next.js.
Consider security implications of rebuilding static pages on demand.
Next.js requires a secret token to secure on-demand revalidation API routes to prevent abuse.