Hi, @peter.oesteritz. I do show those headers being returned for URLs backed by the function. For example:
$ curl --compressed -svo /dev/null 'https://deploy-preview-6--debd-com-2022.netlify.app/api/image?src=%2Fbuild%2F_assets%2Ftest-OUV23Z46.png&width=101' 2>&1 | egrep '^(<|>)'
> GET /api/image?src=%2Fbuild%2F_assets%2Ftest-OUV23Z46.png&width=101 HTTP/2
> Host: deploy-preview-6--debd-com-2022.netlify.app
> user-agent: curl/7.79.1
> accept: */*
> accept-encoding: deflate, gzip
>
< HTTP/2 200
< age: 0
< cache-control: public, max-age=31536000, s-maxage=31536000
< content-type: image/png
< date: Thu, 16 Jun 2022 07:44:52 GMT
< server: Netlify
< x-nf-request-id: 01G5NQHQB70EHD6RCZHXP1EGVS
<
That does show the header cache-control: public, max-age=31536000, s-maxage=31536000 sent and I confirmed that the function is what generated the response.
Please note, the Standard Edge Network is shared. You will never have direct control of the cache there. Even if you use these cache headers, unless your site has very high traffic, the cached URLs are likely to drop out of cache quickly.
Looking at the site in question, there are only 10 request being served by this function in the last 24 hours. Based on that very low traffic level, the URLs will be quickly be ejected from the cache.
This is because this header below is about optional caching only:
cache-control: public, max-age=31536000, s-maxage=31536000
Says that a CDN can optionally cache this URL for 365 days. It does not say the CDN must cache this URL. It says a CDN can cache it if it wants to. Again, as the Standard Edge Network is a shared resource with millions of Starter plan sites on it, low traffic sites will always be quickly ejected from the cache.
So, you are applying the headers correctly. However, the headers are also not causing the images to be cached because the site is low traffic and you are on a shared CDN.
The On-demand Builder functions do allow for caching of the response, even for low traffic sites. The caching is done at the origin (not in the CDN) so a single cached response does persist for all CDN nodes, again, even if the traffic is low.