上QQ阅读APP看书,第一时间看更新
Compression with Express.js
Enabling compression for Express.js saves you and your user bandwidth, and this is pretty easy to do. The following code must also be added to the server index.js file:
app.use(compress());
This middleware compresses all responses going through it. Remember to add it very high in your routing order so that all requests are affected.
Whenever you have middleware like this, or multiple routes matching the same path, you need to check the initialization order. The first matching route is executed unless you run the next command. All routes that are defined afterward will not be executed.