is there a way to custom headers for _next/static/*.js
Answered
Barbary Lion posted this in #help-forum
Barbary LionOP
I have a use case where, I was specifically ask to customise these default headers of next which are these public, max-age=31536000, immutable
Answered by Anay-208
Tell devops team. They are probably using nginx, or amplify. They’ll have to add custom headers from there
28 Replies
You can try to paste in this:
// next.config.js
module.exports = {
async headers() {
return [
{
// Matching route for _next/static/*.js files
source: '/_next/static/:path*',
headers: [
{
key: 'Custom-Header',
value: 'Custom Value', // The value of the custom header
},
],
},
]
},
}Barbary LionOP
this doesn’t get reflected for static chunks
let me check
Barbary LionOP
thanks, I am not deploying on vercel
it's custom
Yes, you're right, let me find another way
@Barbary Lion thanks, I am not deploying on vercel
If you're deploying to vercel, try adding this to
vercel.json :// vercel.json
{
"headers": [
{
"source": "/_next/static/:path*",
"headers": [
{
"key": "auth",
"value": "yes"
}
]
}
]
}or any custom header
I deployed a nextjs app to vercel specifically for this
Barbary LionOP
we have custom server
nothing on vercel
Barbary LionOP
nope, just a node server
So you'll have to configure from that
Or I can help you, if you give me more details
Barbary LionOP
yeah, so it's just using the example Docker File
and, it's hosted on AWS, that's the only detail I know of from our deveops team
devops*
Tell devops team. They are probably using nginx, or amplify. They’ll have to add custom headers from there
Answer
Till then, you’ll have to file an issue on nextjs GitHub
@Anay-208 Tell devops team. They are probably using nginx, or amplify. They’ll have to add custom headers from there
Kind you mark my message as a solution? @Barbary Lion
Barbary LionOP
yes, thanks
just linking the github issue here
for next wanderer
tracking this issue here: https://github.com/vercel/next.js/discussions/60517
@Barbary Lion yes, thanks
Alright.