mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
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.
This commit is contained in:
1 parent
e179bd5b9b
commit
4e5c0fd401
3 files changed
+14
-1
No files matched your search
+4
-1
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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/(?<asset>.+)$ {
|
||||
# Serve gzip sidecars when supported, including requests from reverse proxies.
|
||||
gzip_static on;
|
||||
gzip_proxied any;
|
||||
gzip_vary on;
|
||||
try_files /assets/$asset =404;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user