Static local images using next/image returning max-age=0

Netlify Image CDN is not respecting the cache-control headers unexpectedly returning public,max-age=0,must-revalidate for static local images, whereas NextJS is correctly returning public, max-age=315360000, immutable

Screenshot 2024-04-29 at 5.23.04 PM

sweelee-experience.netlify.app

Is there a way to configure or fix this?

Where is it returning this?

Also, don’t do this.

It can be seen in local development

Have you referred to: Netlify Image CDN | Netlify Docs?

thanks for the reply @hrishikesh, the following config works but I would like to know why the Image CDN is not respecting with NextJS defaults

[[headers]]
  for = "/_next/static/*"
  [headers.values]
    Cache-Control = "public, max-age=604800, immutable"

Image CDN needs its own headers. Next.js config will only work when Next.js server serves the images and that doesn’t happen with the Image CDN.

gotcha, @hrishikesh. last thing I’m curious about is why this max-age 0 is the default, wondering how resources are classified as static or dynamic.

In this case I think it assumes are local assets are dynamic.

Static assets are all the files that don’t invoke a Function or an Edge Function. I don’t think we’re treating local assets are dynamic. The cache-control as you can see always has a max-age 0. The Netlify-CDN-Cache-Control header is set internally and not sent to browser, so you won’t be able to see it.

gotcha, which step in the process is a Function triggered? My understanding is that the flow is something like this

Request → Image CDN → local assets from build

Do let me know if this is wrong

For Image CDN, that’s about right. For Functions, it’s like Request → Netlify CDN → AWS Lambda and then return trip as well.

thanks for the clarification, in this case do requests to _next/image/* trigger a Netlify Function or Image CDN. Ideally we would directly want it to go through Image CDN with the proper return headers.

It directly goes on Image CDN. Functions are not involved here.

sorry @hrishikesh still not getting a solution, then max-age=0 is actually not expected then