Gzip on Spring server or Nginx (reverse proxy)?
If you care about performance: Dont use Nginx for that!
Nginx gzip process is a content filter, this is not compatible with send_file
optimisation (more details at https://docs.nginx.com/nginx/admin-guide/web-server/serving-static-content/#enabling-sendfile):
Enabling the sendfile directive eliminates the step of copying the data into the buffer and enables direct copying data from one file descriptor to another.
As such, I would recommend to use a HTTP proxy for that, (you could use another Nginx! What I am doing all the time), and setup proxy_cache
:
Nginx -- (proxy cache) --> Nginx -- gzip --> CSS/JS files
Most people would recommend enabling it on nginx. The thinking is to free Spring from as much work as possible since:
- Spring uses considerably more memory per request and connection than nginx.
- Spring might hold on to a database connection while it's processing a request. And database connections on the database server are expensive too.
- Spring is more difficult and more expensive to scale up than nginx if the load requires so.
For most setups, the difference will be small and not noticeable. I have never measured it in practice. Other people might have more experience.