在一个项目中发现gzip 没有开启,该项目是用nginx做的反向代理,按说nginx是默认开启gzip 的。但是,我们通过请求看到,request的heraders里是有gzip的但是response的headers里没有。
所以response的gzip 是要在输出的服务处开启。
比如,服务端端是koa2写的,所以,需要在Koa2的服务商开启gzip;
import koaCo from "koa-compress";
server.use(koaCompress({
filter (content_type) {
return /text/i.test(content_type)
},
threshold: 2048,
gzip: { flush: require('zlib').constants.Z_SYNC_FLUSH
},
deflate: { flush: require('zlib').constants.Z_SYNC_FLUSH,
},
br: false // disable brotli
}));