How to Enable GZIP Compression in Spring Boot?

nilan avtar
Nilanchala   |   #Spring Boot   |   Sep 17, 2023, 

HTTP compression is a capability that can be built into web servers and web clients to improve transfer speed and save bandwidth utilisation. The commonly used compression is GZIP.

By default, the gzip compression is disabled in Spring Boot application. However, we can enable compression using the few property changes.

Spring Boot Configuration to enable GZIP Compression

Add the following configuration to spring boot file.

# Enable response compression
# Mime types that should be compressed
server.compression.mime-types=text/xml, text/css, text/javascript, application/json

The above configuration will enable the gzip compression for all responses for the given mime-types defined in the property file.

The wildcard in mime-types are not supported. So we need to explicitly provide all the list of mime-types.

Please note, gzip operation consumes time and a lot of server resources. For this, you may enable the compression-only when the response exceeds a limit.

# Minimum response where compression will kick in

Exclude user-agents from compression.

server.compression.excluded-user-agents= Mozilla/5.0

If you are using YAML configuration file, these properties will look like this:

    enabled: true
    mime-types: text/xml, text/css, text/javascript, application/json
    min-response-size: 1024
    excluded-user-agents: Mozilla/5.0

Read More:

Enable HTTP Response Compression

nilan avtar


I'm a blogger, educator and a full stack developer. Mainly focused on Java, Spring and Micro-service architecture. I love to learn, code, make and break things.