6

I am trying to implement Gzip response compression in my Springboot Rest API

I am using below configuration in my application.properties

# Enable response compression
server.compression.enabled=true

# The comma-separated list of mime types that should be compressed
server.compression.mime-types=text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json

# Compress the response only if the response size is at least 10KB
server.compression.min-response-size=10240

Response compression is happening, but the strange thing is that it is also compression responses having size as low as 1KB or 500B which it should not as server.compression.min-response-size=10240

Shubham Goyal
  • 83
  • 2
  • 5
  • fyi, according to the [documentation](https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html) you could also write 10KB instead of 10240 – Andreas Hacker Nov 27 '18 at 17:30

1 Answers1

1

Are you sure that you are looking at the uncompressed size of the file received, rather than the compressed size actually sent across (as shown in a browsers network tab)?

The web server will check the file size on disc is over the 'server.compression.min-response-size' and compress it if so - this could result in a compressed file being below the value set?

Once the CPU has done the work to compress the file, there is little point then sending the uncompressed version.

Tom Chamberlain
  • 2,955
  • 20
  • 24