服务节点中的gzip文件在浏览器中抛出net :: ERR_CONTENT_DECODING_FAILED
问题描述:
我想要遵循这个以便为一些静态压缩文件提供服务。 https://medium.com/@rajaraodv/two-quick-ways-to-reduce-react-apps-size-in-production-82226605771a服务节点中的gzip文件在浏览器中抛出net :: ERR_CONTENT_DECODING_FAILED
我正在使用webpack压缩插件来生成gzip文件。
在我的服务器上有这个中间件。
app.get('*.js', function (req, res, next) {
req.url = req.url + '.gz';
res.set('Content-Encoding', 'gzip');
next();
});
当我运行的应用程序,在浏览器中我得到 GET http://localhost:8080/app.js网:: ERR_CONTENT_DECODING_FAILED
可能,我还要做更多的东西,但不知道究竟是什么。
谢谢,Ionut
答
看起来像缺少内容类型。在快递服务器中使用此代码:
app.get('*.js', function(req, res, next) {
req.url = req.url + '.gz';
res.set('Content-Encoding', 'gzip');
res.set('Content-Type', 'text/javascript');
next();
});
app.get('*.css', function(req, res, next) {
req.url = req.url + '.gz';
res.set('Content-Encoding', 'gzip');
res.set('Content-Type', 'text/css');
next();
});