From b1322b971e9ff306c6f7a075b3f932bca5e53eb5 Mon Sep 17 00:00:00 2001 From: Bkk1234 Date: Wed, 25 Nov 2026 03:26:41 +0700 Subject: [PATCH] =?UTF-8?q?fix(deploy):=20CSS=20hash=20=E0=B9=80=E0=B8=81?= =?UTF-8?q?=E0=B9=88=E0=B8=B2=E0=B9=84=E0=B8=A1=E0=B9=88=20404=20+=20?= =?UTF-8?q?=E0=B9=80=E0=B8=87=E0=B8=B5=E0=B8=A2=E0=B8=9A=20/=5Fagent-nativ?= =?UTF-8?q?e=20404=20+=20sw=20v2.1.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit จาก audit log จริงบน Dokploy เจอ 2 เคส 1) GET /assets/global-DjioL_Jq.css → 404 (หน้าที่ยังค้างแคช/SW รุ่นก่อนอ้าง CSS hash เก่า) → nginx: ^/assets/*.css ใช้ try_files $uri /assets/global.css → 30-origin.sh คัดลอก assets/global-.css → assets/global.css ตอนสตาร์ท (ไม่ต้อง hardcode hash) 2) GET /_agent-native/auth/session|agent-engine/status, POST /_agent-native/auth/attribution, /__agent-native-chunk-recovery → 404 31KB → nginx: return 204 + access_log off (client chunk ยังยิงอยู่ แต่ไม่กิน log/แบนด์วิดท์) 3) sw.js VERSION v2.1.5 (ล้างแคชหน้าเก่าให้ผู้ใช้) --- docker/30-origin.sh | 10 +++++++++- docker/default.conf.template | 21 +++++++++++++++++++++ sw.js | 2 +- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/docker/30-origin.sh b/docker/30-origin.sh index e198259..bbd87b2 100644 --- a/docker/30-origin.sh +++ b/docker/30-origin.sh @@ -4,6 +4,15 @@ # ไม่ตั้งค่า = ใช้ origin ที่อบมาแล้ว (ไม่มีอะไรเปลี่ยน) set -eu +DOC_ROOT=/usr/share/nginx/html + +# ── CSS alias: request CSS ที่ hash เก่า → ได้ไฟล์ล่าสุด (กันหน้าค้างแคชแล้วไม่มีสไตล์) +css_latest=$(ls "$DOC_ROOT"/assets/global-*.css 2>/dev/null | head -1 || true) +if [ -n "$css_latest" ]; then + cp -f "$css_latest" "$DOC_ROOT/assets/global.css" + echo "css alias: $(basename "$css_latest") -> assets/global.css" +fi + PUBLIC_ORIGIN="${PUBLIC_ORIGIN:-}" BAKED_ORIGIN="${BAKED_ORIGIN:-}" @@ -12,7 +21,6 @@ if [ -z "$PUBLIC_ORIGIN" ] || [ "$PUBLIC_ORIGIN" = "$BAKED_ORIGIN" ]; then exit 0 fi -DOC_ROOT=/usr/share/nginx/html changed=0 for f in $(find "$DOC_ROOT" -type f \( -name '*.html' -o -name '*.xml' -o -name '*.txt' \)); do if grep -qF "$BAKED_ORIGIN" "$f"; then diff --git a/docker/default.conf.template b/docker/default.conf.template index deed9f8..fd6323d 100644 --- a/docker/default.conf.template +++ b/docker/default.conf.template @@ -31,6 +31,18 @@ server { gzip_types text/plain text/css text/xml application/javascript application/json application/xml application/manifest+json image/svg+xml; + # ── agent-native runtime ที่ไม่มี backend ใน static export ──────────── + # client บาง chunk ยังยิง /_agent-native/* (session, agent-engine/status, attribution) + # → ตอบ 204 เงียบ ๆ ไม่ให้ 404 + หน้า 404 31KB กิน log/แบนด์วิดท์ + location ^~ /_agent-native/ { + access_log off; + return 204; + } + location ~ /__agent-native-chunk-recovery$ { + access_log off; + return 204; + } + # ── healthcheck (ไม่ถูก redirect, ไม่ลง log) ────────────────────────── location = /healthz { access_log off; @@ -51,6 +63,15 @@ server { try_files $uri =404; } + # ── CSS: ไฟล์ hash เก่า (หน้าที่ยังค้างแคช/SW รุ่นก่อน) → เสิร์ฟไฟล์ล่าสุดแทน 404 + # 30-origin.sh คัดลอก assets/global-.css → assets/global.css ตอนสตาร์ท + # ทำให้ผู้ใช้ที่เปิดหน้าเก่าค้างไว้ยังได้ CSS ใหม่ (ไม่เจอหน้าที่ไม่มีสไตล์) + location ~ ^/assets/[^/]+\.css$ { + include snippets/security-headers.conf; + add_header Cache-Control "no-cache" always; + try_files $uri /assets/global.css; + } + # ── asset JS/CSS/FONT: revalidate ทุกครั้ง (ไม่ใช้ immutable) ────────── # ในโหมด publish static export เรามัก patch ไฟล์ใน /assets/ ด้วยมือโดยชื่อไฟล์เดิม # → ถ้า cache ยาว เครื่องที่เคยโหลดจะค้างไฟล์เก่าเป็นปี (เคสจริง: CSS scroll/wheel fix ไม่ถึงผู้ใช้) diff --git a/sw.js b/sw.js index e5b00b4..4d80ce9 100644 --- a/sw.js +++ b/sw.js @@ -18,7 +18,7 @@ * | โดเมนอื่น (รูป hotlink) | ไม่จัดการ | * | /app/* · /node_modules/* · /@* | ไม่จัดการ (โมดูลของ dev server) | */ -const VERSION = "v2.1.4"; +const VERSION = "v2.1.5"; const PAGES_CACHE = `alterflixhub-pages-${VERSION}`; const ASSETS_CACHE = `alterflixhub-assets-${VERSION}`;