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; }