From ec2d17b25e835f773fa90386da54c1076eb215f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=85=E5=BF=B5?= Date: Wed, 30 Sep 2026 13:43:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=9D=99=E6=80=81=E8=B5=84=E6=BA=90no-c?= =?UTF-8?q?ache=E5=A4=B4=E2=80=94=E2=80=94=E6=B5=8F=E8=A7=88=E5=99=A8?= =?UTF-8?q?=E5=90=AF=E5=8F=91=E5=BC=8F=E7=BC=93=E5=AD=98=E5=AF=BC=E8=87=B4?= =?UTF-8?q?widget.js=E4=BF=AE=E5=A4=8D=E4=B8=8D=E7=94=9F=E6=95=88(?= =?UTF-8?q?=E7=BA=BF=E4=B8=8A=E4=BA=8B=E4=BB=B6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Code --- app/main.py | 11 +++++++++++ 1 file changed, 11 insertions(+) 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