diff --git a/app/main.py b/app/main.py index 5d0c926..307b0b7 100644 --- a/app/main.py +++ b/app/main.py @@ -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