I am on nuxt 3 and I have a site deployed on netlify. On my site deploy I can clearly see there is an img
folder at the root of the site on netlify.
I have at the site root a _headers
file as well.
img/
└── profile_img.jpg
fonts
_headers
netlify.toml
I am using the netlify image cdn and have an image like this
<img :src
:alt
loading="lazy"
decoding="async"
:srcset="`
/.netlify/images?url=/img/profile_img.jpg&fm=webp&width=1200,
/.netlify/images?url=/img/profile_img.jpg&width=1400 2x,
/.netlify/images?url=/img/profile_img.jpg&fm=webp&width=1600 3x
`"
:sizes="`
(max-width: 767px) 100vw
`">
The network tab shows
Cache-Status: "Netlify Edge"; fwd=stale
What I am trying to get is
Cache-Status: "Netlify Edge"; hit
In my _headers
file I have the following cache-control
header set
/img/*
cache-control: public
cache-control: max-age=604800
cache-control: must-revalidate
According to the docs for customer headers with netlify image cdn
To use custom headers with Netlify Image CDN, apply header rules to your source images.
/source-images/* Cache-Control: public, max-age=604800, must-revalidate
This does not work for me and I see in my network tab
Cache-Control: public,max-age=0,must-revalidate
Cache-Status: "Netlify Edge"; fwd=stale
But if I put this code in the netlify.toml
file at the root I get the desired result
[[headers]]
for = '/img/*'
[headers.values]
cache-control = '''
public,
max-age=604800,
must-revalidate'''
with the response headers
Cache-Control: public,max-age=604800,must-revalidate
Cache-Status: "Netlify Edge"; hit