Run work after a Next.js response with after()
Answer: after() from next/server lets you schedule work to be executed after a response (or prerender) is finished. That is useful for side effects that should not block the response, such as logging and analytics. React's cache() is a different tool: it caches the result of a data fetch or computation in Server Components.
Where after() can run
It can be used in Server Components (including generateMetadata), Server Functions, Route Handlers, and Proxy. You pass a callback that runs after the response or prerender finishes. after is not a Request-time API. Calling it does not make a route dynamic. For a static page, the callback runs at build time or when the page is revalidated. The callback still runs if the response did not complete successfully.
cache() for repeated work
cache is only for use with React Server Components. It lets you cache the result of a data fetch or computation. Use cache() for repeated work in one render. Use after() for work that should run after the response finishes.
| after() | cache() | |---|---| | after() | Runs a callback after the response or prerender | | logging and analytics | Example side effects that should not block the response | | cache() | Caches a fetch or computation in Server Components | | Request-time API | after() is not one and does not force a dynamic route |
See also
Claims
- id: C1 claim: after() schedules work to run after a response or prerender is finished. source: S1 evidence: "after a response (or prerender) is finished"
- id: C2 claim: Calling after() does not cause a route to become dynamic. source: S1 evidence: "does not cause a route to become dynamic"
- id: C3 claim: React cache() caches the result of a data fetch or computation in Server Components. source: S2 evidence: "cache the result of a data fetch or computation"
Sources
- [S1] after. Next.js docs. https://nextjs.org/docs/app/api-reference/functions/after . License: MIT. Accessed 2026-11-19.
- [S2] cache. React docs. https://react.dev/reference/react/cache . License: CC-BY-4.0. Accessed 2026-11-19.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Next.js docs, after; React docs, cache. MIT; CC-BY-4.0. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Next.js docs, after; React docs, cache. MIT; CC-BY-4.0.
Cite this
iinventedlight. 2026. "Run work after a Next.js response with after()." iinventedlight Library, iil:note:7s706ce8, version of 2026-11-19. https://iinventedlight.com/library/notes/nextjs-after/. License: CC-BY-4.0.
@misc{iil_note_7s706ce8,
author = {{iinventedlight}},
title = {{Run work after a Next.js response with after()}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-19},
url = {https://iinventedlight.com/library/notes/nextjs-after/},
note = {Permanent ID iil:note:7s706ce8. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- nextjs-after.table.json (table; CC-BY-4.0)
- nextjs-after.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/nextjs-after.md.