Build Systems/Rendering
ISR and cache invalidation that actually invalidates
Tag granularity, webhook payloads and how to prove a publish reached production in under ten seconds.
Static generation is the easy half. The half that goes wrong is invalidation: an editor publishes, the page does not change, and everyone loses faith in the CMS within a week.
Tag at three levels, not one
A single global tag rebuilds the world on every keystroke-sized edit. A tag per document leaves index pages stale forever. You want both, plus the type in between.
const tags = ["sanity", body._type];
if (body.slug) tags.push(`${body._type}:${body.slug}`);
for (const tag of tags) {
revalidateTag(tag, { expire: 0 });
}Then every read declares which tags it depends on. A doc page tags doc and doc:<slug>; a collection page tags doc only, so publishing any doc refreshes the listing without touching the other doc pages.
The webhook projection matters
Sanity sends whatever projection you configure. Ask for exactly the two fields the route needs and nothing else — a fat payload is a signature-verification failure waiting to happen on a large document.
{_type, "slug": slug.current}_type in [
"post", "caseStudy", "doc", "docCollection",
"category", "tag", "page", "author", "siteSettings", "docsSettings"
]# Should return 401 — proves the signature check is live.
curl -X POST https://example.com/api/revalidate \
-H 'content-type: application/json' \
-d '{"_type":"doc","slug":"anything"}'
# Liveness, no side effects.
curl -s https://example.com/api/revalidate | jqProving it works
- Note the current
ageheader:curl -sI https://example.com/docs/... | grep -i age. - Publish a trivial edit in Studio.
- Poll the same URL.
ageshould reset within a few seconds. - If it does not, check the webhook delivery log in sanity.io/manage — the failure is almost always a secret mismatch.
// related
From the rest of the site.
Rebuilding a logistics marketplace as a content engine
3.1× organic sessions in seven months
- Next.js
- Sanity
- Technical SEO
- Content strategy
SEO in the Next.js App Router: A Field Guide
Metadata, canonicals, structured data and static generation — how the App Router actually wants you to do technical SEO.

