Incremental Static Regeneration keeps pages fast while WordPress remains the editorial source. Time-based
revalidate refreshes stale HTML on a schedule; tag-based revalidateTag lets WP webhooks
bust the cache when content changes.
Fetch from the REST API and set a revalidation interval (seconds).
// app/page.js
import { getHomepageData } from '@/lib/wordpress';
export const revalidate = 60;
export default async function HomePage() {
const data = await getHomepageData();
return <main>{/* render data */}</main>;
}
Use next: { tags: ['homepage'] } so the webhook can target exactly this data.
// lib/wordpress.js
export async function getHomepageData() {
const res = await fetch(
`${process.env.WP_API_URL}/wp-json/wp/v2/pages?slug=home`,
{ next: { tags: ['homepage'] } }
);
return res.json();
}
WordPress (or a plugin) POSTs here after publish; the secret must match your env.
// app/api/revalidate/route.js
import { revalidateTag } from 'next/cache';
import { NextResponse } from 'next/server';
export async function POST(req) {
const { secret, tag } = await req.json();
if (secret !== process.env.REVALIDATION_SECRET)
return NextResponse.json({ error: 'Invalid secret' }, { status: 401 });
revalidateTag(tag);
return NextResponse.json({ revalidated: true, tag });
}
This repo is static HTML only; copy the snippets into a Next.js App Router project with env vars set.