我有一个角度2应用程序,我用cli和gzipped构建。我可以从dist文件夹提供应用程序,但我想提供js文件的.gz版本以进一步提高性能。拦截.js请求并附加.gz与节点和快递
Express服务器文件的尝试:
app.get('*.js', function (req, res, next) {
req.url = req.url + '.gz';
res.set('Content-Encoding', 'gzip');
console.log(req,res);
next();
});
也试过:
app.use(function(req,res,next){
console.log(req,res);
var hello = req.url.split('.');
if(hello[hello.length-1]=='js'){
console.log(req,res);
req.url += '.gz';
res.set('Content-Encoding', 'gzip');
}
next();
});
我能够使用快速压缩中间件,仍然想知道是否有可能截获请求。 – dcatoday
你找到了你的问题的答案?我正试图完成同样的事情。没有运气。 –
嘿@jamesemanon我使用压缩npm包,它运行良好。它将我的网站大小减少到不足200kb,不计算图像。 – dcatoday