Learn to enable HTTP response gzip compression in spring boot 2 applications. The configuration shown in this tutorial can be applied to image compression as well as text compression, both.
By default, compression is disabled in spring boot.
1. Gzip Compression Configuration
The given below response compression properties are applicable to Jetty, Tomcat, and Undertow. Define these properties into
- server.compression.enabled enables or disables the compression.
- server.compression.min-response-size – configures the minimum number of bytes in response for compression to be performed. Default size is
- server.compression.mime-types – enables compressed only if their content type is one of the given mime-type.
Read More : Enable HTTP Response Compression
2. Wildcards in mime-type are not supported
The compression, spring boot relies on support provided by underlying embedded servers. Unfortunately, these servers do not provide any consistent wildcards support in mime-type.
- Jetty is doing strict string comparisons, but it also allows configuring a whitelist/blacklist for this. [Link]
- Tomcat is checking that the response content-type starts with one of the configured mimetypes. So configuring
application/vnd.companywould work for both
Drop me your questions related to Gzip compression in spring boot.
Happy Learning !!