If you run any web service always enable support for serving compressed responses. It will save egress bandwidth costs for you. And, more importantly, for your users. Over time, the servers as well as client devices have become more powerful, so, compressing/decompressing data on the fly is cheap.

For example,

$ curl https://ashishb.net/ > tmp1.htm && du -shc tmp1.htm
32K
$ curl -H 'Accept-encoding: gzip' https://ashishb.net > tmp1.gz && du -shc tmp1.gz
12K
# curl can automatically decompress the response as well
$ curl --compressed https://ashishb.net/

To support this on your servers, handle Accept-encoding. In many cases, you might find standard libraries that support this. For example, for the Go language’s popular Gin framework, it is possible to enable this via middleware.

Here’s a self-contain example demonstrating the same.

// Save this file as server.go
// Then one-time setup
// $ go mod init tmp1 && go mod tidy
// Usage: go run server.go
package main

import (
  "net/http"

  "github.com/gin-contrib/gzip"
  "github.com/gin-gonic/gin"
)

func main() {
  r := gin.Default()
  r.Use(gzip.Gzip(gzip.DefaultCompression))
  r.GET("/ping", func(c *gin.Context) {
    c.JSON(http.StatusOK, gin.H{
      "message": "pong",
    })
  })
  r.Run()
}

Now

# This will produce plain-text output
$ curl localhost:8080/ping
# This will produce compressed binary output
$ curl -H 'Accept-encoding: gzip' localhost:8080/ping -o /dev/stdout
# The compressed binary output can be decoded via the following
$ curl -H 'Accept-encoding: gzip' localhost:8080/ping | gunzip -