From ef9ed54146025f9dfb05951f26f895b373d8a800 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Mon, 28 Sep 2026 13:36:41 -0700 Subject: [PATCH] Drop Precompressed Siblings That Are Not Smaller Than Their Source Caddy serves a .br or .gz sibling whenever one exists, so a tiny file shipped a larger compressed copy than itself. Co-Authored-By: Claude Opus 5.5 --- deploy/make-release.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/deploy/make-release.sh b/deploy/make-release.sh index 46ed0bdc..da20aff0 100755 --- a/deploy/make-release.sh +++ b/deploy/make-release.sh @@ -211,15 +211,23 @@ echo "==> precompressing" have_brotli=0 if command -v brotli >/dev/null; then have_brotli=1; fi +drop_unless_smaller() { + if [ "$(wc -c <"$1")" -ge "$(wc -c <"$2")" ]; then + rm -f -- "$1" + fi +} + precompress() { find "$1" -type f \( -name '*.html' -o -name '*.css' -o -name '*.js' \ -o -name '*.svg' -o -name '*.xml' -o -name '*.json' -o -name '*.txt' \) -print0 | while IFS= read -r -d '' f; do gzip -9 -k -f "$f" + drop_unless_smaller "$f.gz" "$f" # A false test as the last command in a loop body exits the loop non-zero, and pipefail then ends the script. # The if form is required here because this branch exists to tolerate a missing binary. if [ "$have_brotli" = 1 ]; then brotli -q 11 -k -f "$f" + drop_unless_smaller "$f.br" "$f" fi done }