1
0
mirror of https://github.com/alexandrev/xslt-lab.git synced 2026-09-13 08:43:16 +00:00

Perf: add nginx gzip compression and cache headers

- gzip level 6 for JS, CSS, JSON, SVG, fonts
- immutable cache (1yr) for hashed JS/CSS assets
- 7-day cache for static assets (SVG, fonts, images)
- no-store for env.js (runtime config must be fresh)
- no-cache for HTML (SPA index)

Reduces JS transfer from ~460KB to ~115KB gzip.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
alexandrev-tibco
2026-04-17 12:23:46 +02:00
parent 15127af247
commit 1d8faf6b3e
2 changed files with 58 additions and 0 deletions
+1
View File
@@ -9,6 +9,7 @@ RUN npm run build
# Stage 2: serve the static files
FROM nginx:alpine
COPY --from=build /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
EXPOSE 80
+57
View File
@@ -0,0 +1,57 @@
worker_processes auto;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_min_length 1000;
gzip_types
text/plain
text/css
text/javascript
application/javascript
application/json
application/xml
image/svg+xml
font/woff2;
server {
listen 80;
root /usr/share/nginx/html;
index index.html;
# Long-lived cache for hashed assets (JS/CSS chunks)
location ~* \.(js|css)$ {
add_header Cache-Control "public, max-age=31536000, immutable";
try_files $uri =404;
}
# Cache static assets
location ~* \.(svg|ico|png|jpg|jpeg|woff2|woff)$ {
add_header Cache-Control "public, max-age=604800";
try_files $uri =404;
}
# env.js must never be cached (runtime config)
location = /env.js {
add_header Cache-Control "no-store";
try_files $uri =404;
}
# SPA fallback
location / {
try_files $uri $uri/ /index.html;
add_header Cache-Control "no-cache";
}
}
}