I think the default value of server.compression.enabled
should be changed from false
to true
in an upcoming version of Spring Boot (perhaps even 2.3.0? Yes, I'm optimistic).
I don't believe that there's any downside to server.compression.enabled=true
. Years ago, the extra CPU consumption of compression may have been a concern, but I think the time for that worry has passed - the reduced network transfer is far more important for the almost all situations. The default values of server.compression.mime-types
and server.compression.min-response-size
ensure that compression won't compress things uselessly, too.
If there are reasons for compression to be off, I think the documentation should be updated to explain them to users. See https://docs.spring.io/spring-boot/docs/2.2.x/reference/htmlsingle/#how-to-enable-http-response-compression
Comment From: philwebb
I'll flag this issue to see if anyone on the team can remember why we don't enable it by default (perhaps it was just for back compatibility). I feel like it's quite late to be changing the default for 2.3, ideally we'd make such a change before we cut the RC.
Comment From: wilkinsona
IIRC, we don't enable it by default as we want to align with the defaults of the containers that we embed. The containers haven't changed their defaults so we're aligned at the moment.
Comment From: philwebb
Thanks for the suggestion, but we think it's best to stick to the same defaults as the servlet containers.
Comment From: candrews
I don't really understand why the defaults used by servlet containers are relevant. Spring Boot already does plenty that's beyond what servlet containers do.
Furthermore, some of the containers, such as Jetty and Undertow, are configured programmatically more or less from scratch - enabling compression by default doesn't seem like it makes sense as they don't really have "defaults."
For Tomcat at least, I've requested they enable compress by default at https://bz.apache.org/bugzilla/show_bug.cgi?id=64431
Comment From: wilkinsona
Both Tomcat and Jetty have defaults when they're packaged in their zip distributions. When using its distribution, Jetty requires you to enable its gzip.mod
module to enable gzip compression. Undertow itself doesn't have such a distribution, but Wildfly is the next best thing. It does not enable gzip compression by default either.
Comment From: philwebb
Just to add a bit more background about the team discussion we had around this. We still feel like there's a trade-off between CPU and bandwidth that would affect when users would want to enabled gzip compression. If you're developing a public-facing application then it's probably likely gzip compression would be worthwhile. If, however, you're a microservice application and you're in a dataceter, you may well prefer to reduce CPU load because you know you'll only be talking to other microservices and you have a reliable gigabit network.
In short, there's still a trade-off to be made and we don't feel confident that enabling gzip by default will always have a positive effect. Aligning with other servlet container distributions seems like the most sensible action.