fix(deploy): CSS hash เก่าไม่ 404 + เงียบ /_agent-native 404 + sw v2.1.5

จาก 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-<hash>.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 (ล้างแคชหน้าเก่าให้ผู้ใช้)
This commit is contained in:
Bkk1234 committed 2026-11-25 03:26:41 +07:00
1 parent 29ddae9505
commit b1322b971e
3 files changed
+31 -2

No files matched your search

+21
View File
@@ -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-<hash>.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 ไม่ถึงผู้ใช้)