Brotli is a modern compression algorithm for the web to replace the aged Gzip. Developed by Google it is currently supported in all major browsers:

Can I Bro?

Used with a medium compresson level (e.g. 5) it can both be faster and produce smaller payload sizes than Gzip, win win!

Unlike Perl it’s common to run Go servers without a front-end server like nginx infront, therefore we wanted the ability to generate brotli encoded content in Go. The result is negroni-brotli:

package main

import (
    "net/http"

    "github.com/cv-library/negroni-brotli"
    "github.com/urfave/negroni"
)

func main() {
    mux := http.NewServeMux()
    mux.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
        w.WriteHeader(http.StatusNoContent)
    })

    n := negroni.Classic()
    n.Use(brotli.New(5))
    n.UseHandler(mux)
    n.Run(":1337")
}