Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring gzip vs Tomcat gzip

I would like to enable GZIP compression for my web application. I searched over the Internet and found 2 different options:

  • Enable compression in embedded container like described in Spring docs (https://docs.spring.io/spring-boot/docs/current/reference/html/howto-embedded-servlet-containers.html - latest section)
  • Use GzipResourceResolver resolver like described here: http://kielczewski.eu/2014/11/static-resources-in-spring41/

Both options is okay for me but I want to understand the difference and which approach is better. Please assist.

In addition, what will happen if I enable both options? Will servlet container try to compress already compressed files?

p.s. In my opinion 2nd options will be faster as there no need to compress response each time - compressed files will be prepared during build phase.

like image 567
Arthur Gurov Avatar asked Feb 01 '16 12:02

Arthur Gurov


People also ask

Is GZIP better?

Crucially, GZIP is much faster server-side compared to Brotli — lower end devices and/or servers will run better with the older compression technique.

Does GZIP improve performance?

Gzip is a fast and easy way to improve page speed performance while still delivering a high-quality experience to your users. See if your website supports gzip by running a free speed test, and sign up for a free trial for more insights into your website's performance.

Should I use GZIP compression?

Why Do We Use GZIP Compression? GZIP is effective, but it's not the only compression method out there. In fact, it's not even the best method in terms of size reduction. GZIP can reduce the amount of data by up to 70%.


1 Answers

If both compressions are enabled , compression would be done at both the layers. As per spring docs, there is an overhead at server in enabling spring gzip compression . If you have application deployed in container like tomcat, compression can be enabled there as well. But enabling compression at container like tomcat is better as it will be applicable for all the resources(Js, images etc) as compared to enabling gzip compression at spring which might be serving a part of resources. Also double compressing a gzip file would add to overhead and there wont be any significant compression achieved.

like image 176
Vineet Kasat Avatar answered Oct 31 '22 07:10

Vineet Kasat