Featured image of post How to compress static site to Brotli and Gzip

How to compress static site to Brotli and Gzip

If you deploy your static site to a Web server like Caddy, you might need to pre-compress it, especially if you want to use Brotli with Caddy as it’s only supported for pre-compressed assets.

Brotli

1
2
find www.new -type f \( -name '*.html' -o -name '*.js' -o -name '*.css' -o -name '*.xml' -o -name '*.svg' \) \
  -exec /bin/sh -c 'brotli -q 11 -o "$1.br" "$1"' /bin/sh {} \;

Gzip

1
2
find www.new -type f \( -name '*.html' -o -name '*.js' -o -name '*.css' -o -name '*.xml' -o -name '*.svg' \) \
  -exec /bin/sh -c 'gzip -v -f -9 -c "$1" > "$1.gz"' /bin/sh {} \;

Source

https://github.com/maruel/hugo-tidy/blob/main/docker-entrypoint.sh#L49

FarisZR
Built with Hugo
Theme Stack designed by Jimmy