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

More Next.js tasks

Back to the full Next.js cheat sheet