Skip to content
Discussion options

You must be logged in to vote

server.headers on some Vite versions only gets applied to the HTML responses, not to transformed modules or assets. That's exactly the symptom you're describing, index.html has the headers and everything else doesn't.

Workaround that works on any version: set them yourself in a middleware plugin so every response gets them.

{
 name: 'coop-coep'
 configureServer(server) {
 server.middlewares.use((req, res, next) => {
 res.setHeader('Cross-Origin-Opener-Policy', 'same-origin')
 res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp')
 next()
 })
 }
}

Also worth checking your Vite version, this was fixed so server.headers covers all dev responses on recent releases. If you're already on…

Replies: 4 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@solodeveloping
Comment options

Comment options

You must be logged in to vote
1 reply
@solodeveloping
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by solodeveloping
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
3 participants
Converted from issue

This discussion was converted from issue #22235 on April 14, 2026 14:27.

⌂ 换网址