admin管理员组文章数量:1355522
I need to set Cache-Control
header with a dynamic value in getInitialProps
method. I tried the below.
if(context.res){
context.res.setHeader('Cache-Control','My-Cache-Control');
context.res.setHeader('My-Header','My-Value');
}
But it looks looks like NextJs is overriding the header value before sending the response. Below is the cache-control
header value in response header in browser.
Cache-Control: no-store, must-revalidate
My-Header: My-Value
Let me know if anything is missing.
I need to set Cache-Control
header with a dynamic value in getInitialProps
method. I tried the below.
if(context.res){
context.res.setHeader('Cache-Control','My-Cache-Control');
context.res.setHeader('My-Header','My-Value');
}
But it looks looks like NextJs is overriding the header value before sending the response. Below is the cache-control
header value in response header in browser.
Cache-Control: no-store, must-revalidate
My-Header: My-Value
Let me know if anything is missing.
Share Improve this question asked Jan 10, 2018 at 10:10 Cyril Sadasivan PanickerCyril Sadasivan Panicker 691 silver badge4 bronze badges2 Answers
Reset to default 4Cache-Control
headers are overridden in development, so that pages do not get cached by the browser.
It will work in production (next build && next start
).
as mentioned in this github bug
use res.setHeader()
res is a Node.js http.ServerResponse
本文标签: javascriptSet cachecontrol header in getInitialProps() in NextJsStack Overflow
版权声明:本文标题:javascript - Set cache-control header in getInitialProps() in NextJs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743974155a2570808.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论