NextJS determine in Edge Function if origin response was cached or not

Hi folks. Our site uses Edge Functions and NextJS (SSR). From within my Edge Function code, I’m hoping to determine if the NextJS response for the current request was cached or if the NextJS SSR handler actually had to generate the page. Is there any way to determine this for sure from EF code?

I think I could infer from a very low “age” Header that the response was a cache-miss/generation, but that seems like an imperfect way to go about it. Wondering if there’s any way to determine for sure if it was a cache-hit/miss. Thanks.

Heya @Jesse_Lee !

For the most part, your Edge function would be running before the SSR route is executed, so it seems a bit horse-before-the-cart to be trying to determine if a not-yet-executed lambda is cached or not. But, I expect I am misunderstanding something you will clear up in a response.

Note that you cannot infer much from the Age HTTP response header since that is stored per CDN node and will only reflect that node’s cache; and, there is not a good way to target a specific node from your code.

Could you share a bit more about the request cycle you envision (you don’t need to share any path to your asset, but something like:

“browser makes request which is intercepted by my Edge Function, which then makes a request to my lambda ISR route and wants to see if the response was a result of a previous run, or if it was run in real-time” ?

As an FYI you are always allowed to ask questions directly of our helpdesk based on your account level and we would have seen and responded to this much more quickly there! Let me know if you need more guidance on how to file a support ticket that way. Happy to work in public as well as this information does seem of general interest to our community, but you don’t need to wait for us to answer here where we cannot provide an SLA on response time as we can in our helpdesk for you.