Next.js Discord

Discord Forum

is there a way to custom headers for _next/static/*.js

Answered
Barbary Lion posted this in #help-forum
Open in Discord
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
View full answer

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
@Barbary Lion I've confirmed it, it works if you add it to vercel.json
I deployed a nextjs app to vercel specifically for this
Barbary LionOP
we have custom server
nothing on vercel
@Barbary Lion we have custom server
Nginx?
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
Barbary LionOP
yes, thanks
just linking the github issue here
for next wanderer
@Barbary Lion yes, thanks
Alright.