From 4e5c0fd4011835a2852d82294c6f453c398bf023 Mon Sep 17 00:00:00 2001 From: Philipp <49908921+pwuersch@users.noreply.github.com> Date: Sat, 3 Oct 2026 21:03:22 +0200 Subject: [PATCH] fix(docker): serve precompressed static assets (#583) Generate gzip sidecars for JavaScript, CSS, and WebAssembly assets during the image build. Serve them through nginx when clients accept gzip, including proxied requests, while preserving uncompressed fallback and runtime HTML base-path rewriting. --- Dockerfile | 5 ++++- README.md | 6 ++++++ nginx.conf | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d85ef6d7..931a887a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,7 +20,10 @@ COPY . . ARG VITE_AVAILABLE_LOCALES ENV VITE_AVAILABLE_LOCALES=${VITE_AVAILABLE_LOCALES} ENV VITE_VERCEL_ENV=production -RUN pnpm build +# Precompress hashed assets once instead of compressing each response at runtime. +RUN pnpm build \ + && find dist/assets -type f \( -name '*.js' -o -name '*.mjs' -o -name '*.css' -o -name '*.wasm' \) \ + -exec gzip -9 -n -k {} + # production stage FROM nginxinc/nginx-unprivileged:stable-alpine@sha256:4714e0b1b2577eaa1a6131d07c958b67f0eb68e6d0521e90c6e5287db8cf0bc5 AS production-stage diff --git a/README.md b/README.md index c41b885c..2f045337 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,12 @@ docker run --pull always --restart unless-stopped -p 8080:8080 sharevb/it-tools: Other existing docker tags: `latest-en` (english only) +Container builds precompress JavaScript, CSS, and WebAssembly files in `dist/assets`. +Nginx serves the `.gz` sidecars when clients accept gzip, including requests forwarded +by reverse proxies, and otherwise serves the original files. Compression happens once +at build time rather than on every request. HTML remains uncompressed so runtime +`BASE_URL` rewriting continues to work. + ## Use in Docker Compose file ```yml diff --git a/nginx.conf b/nginx.conf index cf18b407..c6518f77 100644 --- a/nginx.conf +++ b/nginx.conf @@ -53,6 +53,10 @@ server { # index.html below and is served as text/html with a 200, which the browser rejects # with an opaque MIME error instead of a plain 404. location ~ ^/(?:.*/)?assets/(?.+)$ { + # Serve gzip sidecars when supported, including requests from reverse proxies. + gzip_static on; + gzip_proxied any; + gzip_vary on; try_files /assets/$asset =404; }