Gzipping is a compression algorithm widely understood by browsers. Your server will serve compressed responses, which will consume a few more CPU cycles but will save bandwidth.
The client browser will then be charged for unzipping the resources and displaying them to the user.
To leverage Tomcat's Gzipping abilities, simply add the following line to the application-prod.properties
file:
server.tomcat.compression=on server.tomcat.compressableMimeTypes=text/html,text/xml,text/css,text/plain, application/json,application/xml,application/javascript
This will enable Tomcat's Gzipping compression when serving any file matching the MIME types specified in the list, and whose length is greater than 2048 bytes. You can set server.tomcat.compression
to force
to enforce compression or set it to a numerical value if you want to change the value for the minimal length of Gzipped assets.
If you want more control over the compression, say over the level of compression, or want to exclude user agents from compression, you can use the GzipFilter
class in Jetty by adding the org.eclipse.jetty:jetty-servlets
dependency to your project.
This will automatically trigger the GzipFilterAutoConfiguration
class, which can be configured with a handful of properties prefixed by spring.http.gzip
. Have a look at GzipFilterProperties
to understand its level of customization.
Refer to the documentation at http://docs.spring.io/spring-boot/docs/current/reference/html/howto-embedded-servlet-containers.html#how-to-enable-http-response-compression for additional information.