我正在发送 .br brotli 压缩文件的获取请求:
const resp = await fetch("/hello-world.wasm.br")
在 Chrome 网络选项卡中,我看到没有 Accept-Encoding 标头。
服务器使用正确的 Content-Encoding 标头进行响应,但浏览器不会解压缩响应。
如何让 fetch 使用压缩内容编码?
您可以在获取请求中显式设置 Accept-Encoding 标头,如下所示。
const resp = await fetch("hello-world.wasm.br",
{
headers: {
"Accept-Encoding" : Here you specify the supported content encoding
}
})
有关 fetch-api 的更多信息,请参阅以下链接: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
希望它有效!如果不起作用请告诉我。