When working with the compression module, you need to remember two subtle points:
If the response body is less than the value specified in the threshold parameter, the response will not be compressed. This saves server resources in cases where compression does not give a significant gain to the client. By default, compression uses the value of 1kb .
Not all files should be compressed. For example, applying compression to image/png files, in some cases, can increase their size. In the compression module, there is a filter parameter. The value of this parameter is a function that determines whether a response should be compressed. The default module is compressible , which allows compression only for text files (with text/* and application/json mime types).
Thus, if you really want to compress all server responses, you need to use this code:
var express = require('express'), compression = require('compression'), app = express(); app.use(compression({ // Π‘ΠΆΠΈΠΌΠ°Π΅ΠΌ HTTP ΠΎΡΠ²Π΅ΡΡ, ΡΠ΅Π»ΠΎ ΠΊΠΎΡΠΎΡΡΡ
Π΄Π»ΠΈΠ½Π½Π΅Π΅ ΠΎΠ΄Π½ΠΎΠ³ΠΎ Π±Π°ΠΉΡΠ° threshold: 1, // Π‘ΠΆΠΈΠΌΠ°Π΅ΠΌ HTTP ΠΎΡΠ²Π΅ΡΡ Π½Π΅Π·Π°Π²ΠΈΡΠΈΠΌΠΎ ΠΎΡ ΠΈΡ
mime-ΡΠΈΠΏΠ° filter: function() {return true;} })); app.use(express.static(rootDir));