after() & Revalidation Helpers in Next.js
From the Next.js cheat sheet ยท Advanced Routing & Modern Features ยท verified Jul 2026
after() & Revalidation Helpers
Run work after the response + cache invalidation API
typescript
import { after } from 'next/server'
import { revalidateTag, revalidatePath } from 'next/cache'
export async function POST(req: Request) {
const data = await req.json()
const post = await db.post.create({ data })
// Work that should NOT block the response:
after(async () => {
await sendEmail(post.authorEmail, 'Your post is live')
await track('post.created', { id: post.id })
})
// Targeted cache invalidation:
revalidateTag(`posts:author:${post.authorId}`)
revalidatePath('/feed')
return Response.json(post)
}๐ก after() runs callbacks post-response โ no impact on user latency
๐ revalidateTag pairs with `fetch(url, { next: { tags: [...] } })`
โก revalidatePath busts a page/layout; revalidateTag is surgical
๐ฏ Use after() for emails, analytics, and webhook fan-out after mutations
cachingserver-actionsmodern