根据Netlify docs for custom headers,我可以创建一个使用自定义标题的路径
# use these headers for the /index.html file
/index.html
Cache-Control: max-age=31536000, public
但是,我似乎无法弄清楚的是,如果我可以使用相同的标头而不必为每个路径创建一个新条目,那么我可以使用多个路径
/*.js
Cache-Control: max-age=31536000, public
/*.css
Cache-Control: max-age=31536000, public
我已尝试过以下操作,但没有一个工作
/*.js /*.css
Cache-Control: max-age=31536000, public
/*.js
/*.css
Cache-Control: max-age=31536000, public
/*.js, /*.css
Cache-Control: max-age=31536000, public
答案 0 :(得分:3)
Diclaimer: I work for Netlify.
Our header file format isn't that flexible - you'll need one rule per globbed path (e.g. /*.css
). Some folks who have complex needs generate the file programatically:
find . -name assets -type d -exec echo "{}/*.css:\n Header: value" >> public/_headers
or something similar to that.
However - be very careful manipulating the cache control settings! We choose them with GREAT care as explained in this article:
https://www.netlify.com/blog/2017/02/23/better-living-through-caching/
to support atomic rollbacks and deploys.
If you change them, you'll get negligible performance increases at the risk of totally removing the ability to update those files for return visitors. One assumes you're using cachebusting or asset fingerprinted URL's so that those URL's change each deploy and/or whenever content changes?
Regardless, that's not even the best way to solve that problem. Our asset optimization does all of that for you already:
This IS safe since those URL's are asset-fingerprinted - any change in content changes the URL's. You activate this near the bottom of your Build & Deploy settings page and it is free at all account levels.
I'd write in to our support team for more guidance. If you're seeing terrible performance or something you're trying to overcome here - we'd love to help you fix the root cause rather than see you potentially break your site with long-lasting bad effects.