How to enable GZIP compression in Spring Boot application?

June 27, 2019 No comments gzip compression QA Spring Boot

Compressing static resources is a great way to save bandwidth and improve user experience. This is also the easiest way to speed up page loading which affects SEO in a positive way. The best and commonly used compression is GZIP. This kind of compression is disabled in Spring Boot by default but fortunately, we can enable it by setting below parameters in file.

# Whether response compression is enabled.

# List of user-agents to exclude from compression.

# Comma-separated list of MIME types that should be compressed. Default mime-types are: text/html, text/xml, text/plain, text/css

# Minimum "Content-Length" value that is required for compression to be performed.

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

        enabled: true
        mime-types: text/html,text/xml,text/plain,text/css,text/javascript,application/javascript 
        min-response-size: 2048

To find out if everything was correctly configured, check response headers for files choosed for compression. There should be Content-Encoding header with gzip value, also these files should be definitely smaller then before compression. How to enable gzip compression in spring boot

{{ message }}

{{ 'Comments are closed.' | trans }}