Spring Boot: Response Compression

Hi Guys,

Spring boot provides a facility to compress your resources by changing minimum configuration. Below is the available properties related to compression, it should be added into your configuration file (usually application.properties file).

This is a flag to enable response compression.
Possible values = true or false

You can give list of user-agents which needs to be exclude from compression.
Example Values: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0

You can give Comma-separated list of MIME types that should be compressed.
Example values: application/json,application/xml,text/html,text/xml,text/plain,text/css,application/javascript,application/json

Using this property you can restrict compression based on response size in bytes. Value is minimum response size that is required for compression to be performed.
Example value: 2048

After enabling compression you can check your response size by inspecting using firebug (that what i have used) or some other inspection tool. And also you can find “Content-Encoding=gzip” in your response headers.

Please remove build tools from your dependency(from pom.xml in case of maven and build.gradle in case of gradle) as it ignore compression properties and loads your resources without compression.

It is always advisable to ignore buildtools for production environment.


That’s it for boot compression methods.

I want to discuss one more thing related to compression here, while looking best methods or tools for response compression i came to visit one portal which is provided by google.

It provides a web based methods to compress a javascript, you can find out more here.

The most useful thing found here is code refactoring,

  • it minimize a variable name
  • convert inline if condition
  • convert if…else clause to ternary operator

and many more changes which will help us to reduce our script content.

Share current post by copy: https://goo.gl/jPtRrv
Hope it may help you somewhere.
Happy learning :).

Yogesh P