Tutorials Spring Boot How to Enable GZIP Compression in Spring Boot?

How to Enable GZIP Compression in Spring Boot?

HTTP compression is a capability that can be built into web servers and web clients to improve transfer speed and save bandwidth utilization.

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 application.properties file.

# Enable response compression
server.compression.enabled=true
 
# 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
server.compression.min-response-size=4096

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:

server:
  compression:
    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
User-Agent

Total
2
Shares
guest
0 Comments
Inline Feedbacks
View all comments
Previous Post

Git Commands Cheat Sheet

Next Post

How to Clear the Local DNS Cache in Mac OS?

Related Posts
By clicking “Allow All”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. Cookie Notice
Allow All
0
Would love your thoughts, please comment.x
()
x