-
Notifications
You must be signed in to change notification settings - Fork 26.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set proper Cache-Control max-age for static assets #1791
Comments
That idea is that you set a CDN, I think the Next static folder it's only for development usage. |
@dbo since we don't hash static files, we are not possible to do that. We should improve this behavior in the future. But it's not happening anytime sooner. |
@arunoda So if it's generally discouraged to be used on zeit/now (other than during dev-time), I think it's worth to be stressed out in the README. |
I ran into this problem when using CloudFlare as a CDN. It takes the cache settings from the origin server (max-age=0), so all assets in /static/ are not cached despite being on the CDN. A next.js config setting would be nice as an improvement at some point, but a workaround if using Express as a server is pretty easy:
It needs to come before the next catch-all '*' route in your server.js to take effect. |
@mike-low Mine is like
|
@sergiodxa Probably at least files from _next should get non-zero max age by default as they are in hashed folders. |
Any plan to change that one day? Having expire headers is quite common and a recommended practice |
This comment has been minimized.
This comment has been minimized.
@bovas85 I've hidden your comment as it's related to Nuxt.js, not Next.js. |
Sorry! I read nuxt and commented 👎 my bad :) |
@bovas85 no worries at all 😄 |
i tried providing |
This works for I put this line right above this one, as suggested:
Response header cache-control max-age is still 0 for CSS files coming from |
Same here. I have the following, which is not working
|
@DaleOC @geochanto @fabb I had the same issue. Eventually got it:
|
How about changing "Cache-Control" for production whereas no custom Node server is running? I.e. pure NextJS UPD.
|
So all of you suggest me move my It should be some how without custom server ability to add custom headers to static files. So just letting others to know how it could be solved without custom server async headers() {
return [
{
source: '/:all*(svg|jpg|png)',
locale: false,
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=9999999999, must-revalidate',
}
],
},
]
}, |
@FDiskas does this work and in what folder needs your code to be add ? next.config.js ? |
@manziEric look: just add your BUT if you don’t like the Cache-Control header that is set by default, you may change it, according to documentation. More info in my previous answer with the links: #1791 (comment) (and yes, these changes are being done via |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
I am missing a proper max-age resp. Cache-Control header set for
/static
assets (serve
defaults to setmax-age
to 0). I plan to invalidate/bust the browser cache using query parameters on these. Shouldn't static assets always be served with long max-age?The text was updated successfully, but these errors were encountered: