我已经压缩了webpack捆绑包,当我尝试提供它时,在客户端出现ERR_CONTENT_DECODING_FAILED
错误。
这是我的中间件:
`app.get('*.js', function (req, res, next) {
req.url = req.url + '.gz';
res.set('Content-Encoding', 'gzip');
res.set('Content-Type', 'text/javascript');
next();
});`
有人对发生的事情有任何想法吗?我尝试使用
.header()
或.setHeader()
方法,但是也没有得到任何想要的结果。提前致谢。
这是压缩插件:
new CompressionPlugin({
asset: "[path].gz[query]",
algorithm: "gzip",
test: /\.js$/,
threshold: 10240,
minRatio: 0.8
})
最佳答案
我只是通过放置以下中间件声明来解决了这个问题:
app.get('*.js', function (req, res, next) {
req.url = req.url + '.gz';
res.set('Content-Encoding', 'gzip');
res.set('Content-Type', 'text/javascript');
console.log('sent')
next();
});
在
app.use('/static', Express.static('dist'));
之前。 (反之亦然)