Next.js · Middle · Question 36 of 75

How do you run code (e.g. analytics) after the response is sent, without delaying the user?

Explanation

after(() => log(...)) schedules work after the response finishes (in server components, Server Actions, Route Handlers, proxy). A "dangling" promise in a serverless environment can be cut off when the function ends, and its errors get lost.

Further reading

Problem with a question

Next.js · Middle · question 36

Test yourself

Take the Next.js · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz