In netlify.toml, you can set custom headers like this:
[[headers]]
for = "/*.(jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)"
What’s the format for this glob? Will /* match subdirectories? Is it equivalent to this regex ^/.*\.(jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$?
Glad that format is working for you! It may stop working at any time, so if you want our advice, you’ve got it, and I think the peace of mind around changing one rule for 7 is totally worthwhile.
And you’re right - we would never ever add that particular header - our default caching is very carefully considered and your configuration (setting a long cache timeout) is a worst practice for most folks who do it without thinking it through. I guess you’ve probably seen this article, but in case you haven’t:
Not saying you need to change things - you seem pretty thoughtful and I guess you know you’ll not want to change a css file in the next year (though that seems quite suspect to me now that I say it out loud - for a font it makes sense, but really, for css?). I have just have spent so many hours troubleshooting for folks who set a timeout like that, and had to rename all their files to “dodge” their old, bad config - it’s super hard for us to debug since all we know is “that file is changed in our database” - we can’t see past caching headers settings easily.
But anyway, now you know the full story and can make the decisions that match your desired risk level and meet your goals best!
My CSS file names are hashed, so there should never be a reason to use the same filename with old content.
Okay, good to know that my configuration working was only a coincidence and not by design. That was what I opened this issue to figure out: I’ve had this configuration for a while, but when I was reading the docs I couldn’t figure out why it actually worked. I guess the answer is that Netlify is using some globbing library internally today but might not tomorrow. I’ll change it when I get a chance.
Why it is not working in my case. `[[headers]]
for = “/*.js”
[headers.values]
cache-control = “max-age=31536000”
for = "/*.css"
[headers.values]
cache-control = "max-age=31536000"
for = "/*.woff"
[headers.values]
cache-control = "max-age=31536000"
for = "/*.png"
[headers.values]
cache-control = "max-age=31536000"
`
Here only the .js file gets bundled but in the network tab, I see for: “/*.png” on bundle.js header. That means bundle.js is getting the header for “/*png”. Why? And why other are not working?