Performance: On-demand revalidation
MEDIUM IMPACT
On-demand revalidation affects how quickly updated content appears without rebuilding the entire site, impacting page load speed and freshness.
import { NextApiRequest, NextApiResponse } from 'next'; export default async function handler(req, res) { // Trigger revalidation for specific path await res.revalidate('/path-to-update'); res.json({ revalidated: true }); } // Only updated pages rebuild on demand
export async function getStaticProps() { // fetch data return { props: { data }, revalidate: 60 }; } // Full site rebuild triggered on every change or long revalidate interval
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Full static rebuild on every change | N/A (server-side) | N/A | Blocks LCP until rebuild completes | [X] Bad |
| On-demand revalidation for specific pages | N/A (server-side) | N/A | Minimal impact on LCP, fast update | [OK] Good |