fix: 静态资源no-cache头——浏览器启发式缓存导致widget.js修复不生效(线上事件)

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-09-30 13:43:09 +08:00
parent 348e74b36b
commit ec2d17b25e
+11
View File
@@ -58,6 +58,17 @@ app.include_router(chat_rest_router)
app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static")
@app.middleware("http")
async def static_no_cache(request, call_next):
"""静态资源协商缓存(2026-09-30 线上事件): 无 Cache-Control 时浏览器对
widget.js 走启发式缓存,修复部署后用户端仍跑旧脚本。no-cache=每次用
etag 轻量协商,有更新即时生效,未变则 304 几乎零开销。"""
resp = await call_next(request)
if request.url.path.startswith("/static/"):
resp.headers["Cache-Control"] = "no-cache"
return resp
@app.get("/")
async def index():
from fastapi.responses import FileResponse