-
Notifications
You must be signed in to change notification settings - Fork 0
[R][2] Topic: Compression (Jelmer Overeem)
To improve the speed of the web application we chose to use gzip compression to decrease the size of the response body. We used the npm package compression for this. It is middleware for gzip compression in the Express application.
Gzip compression is a way to compress files/assets so the network can transfer them faster. Gzip is a program based on an algorithm. It is one of the most used compression methods on the web.
This package is a compression middleware that supports two compression ways:
- deflate
- gzip
The middleware will compress the response bodies that traverse through the middleware based on specific options you can give.
Filter
You can set a filter for the middleware to decide if the response should be compressed.
Level
You can set a level for the zlib compression. A higher level will give you better compression, but it takes more time to complete. A lower level gives you less compression but is faster.
memLevel
With memLevel you can specify how much memory should be assigned for the compression state.
Strategy
Strategy can be used to "tune" the compression algorithm, this only affects the compression ratio.
res.flush
res.flush()
is a method to force the compressed response to be flushed to the client.
Wilson, D. (2019, March 18). npm: compression. Retrieved April 11, 2020, from https://www.npmjs.com/package/compression
Sexton, P. (2016, May 27). How to enable compression and gzip for page speed. Retrieved April 11, 2020, from https://varvy.com/pagespeed/enable-compression.html
Performance Best Practices Using Express in Production. (n.d.). Retrieved April 11, 2020, from https://expressjs.com/en/advanced/best-practice-performance.html#use-gzip-compression