We have a conventional content website that is deployed on netlify. By design, practically all the assets excepting the HTML files, are immutable. I am trying to configure the headers in netlify.toml to set a longer max-age for all jpg files in the directory tree (dozens of them). I tried the following
The wildcard will match anything until the end of the URL. The rule above is essentially the same as this (without “.jpg”:
/foo/*
Cache-Control: public, max-age=604800
So it is working only because the path matches, not because of the file extension. There is no way to write a rule that matches the file extension at this time.
The recommended workaround would be to put all the assets that require a special header into a subdomain (as you have done) and apply the rule to the contents of that directory.
If there are other questions about this, please let us know.
Does the path /foo/*.js match all files in /foo? It seems like “html” files in those directories still get the standard netlify cache control headers, rather than the ones I’m specifying.
You should actually be able to do what you’re trying to do. Can you make cache-control lowercase? That should work then. The case has to match in order for it to override our default headers.
It does actually work as is (without lowercasing “cache-control”). It would be nice if the question of wild-card matches (do the extensions work as they seem to be) could be authoritatively answered.
Either @luke is correct or futuregerald and @fool are correct, but all of the posts can’t be true.
Can you use file extensions after a wildcard like /dir/*.html and /dir/*.jpg or not?
Also can you use double wildcards for directories like /dir/**/*.html and /dir/**/*.jpg or not?
There seems to be a lot of conflicting information (even from the Netlify team) about both the syntax and capabilities of the header directives across this forum so a little clarity would be much appreciated. Thank you.