You could configure it the server. Before that, you need to know which web server you use. It can be nodejs, nginx, apache etc
But instead of doing that in your server, I would suggest giving that work to Cloudflare. They'll take care of it. They also use brotli (better than gzip) whenever possible