From 74f9688ba14cca36b032d3d4490028c3efa2d628 Mon Sep 17 00:00:00 2001 From: gouki Date: Sat, 8 Aug 2026 23:42:40 +0000 Subject: [PATCH] =?UTF-8?q?fix(cache):=20=E5=85=A5=E5=8F=A3HTML=E5=8A=A0no?= =?UTF-8?q?-cache,=E6=9D=9C=E7=BB=9D=E5=90=AF=E5=8F=91=E5=BC=8F=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E6=8C=81=E6=9C=89=E6=97=A7=3Fv=3D=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7=E5=AF=BC=E8=87=B4=E9=83=A8=E7=BD=B2=E5=90=8E=E7=9C=8B?= =?UTF-8?q?=E5=88=B0=E6=97=A7=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VERSION | 2 +- app/main.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/VERSION b/VERSION index 1c09c74..42045ac 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.3 +0.3.4 diff --git a/app/main.py b/app/main.py index 3fc7223..dcc59d6 100644 --- a/app/main.py +++ b/app/main.py @@ -132,12 +132,16 @@ app.mount("/static", NoCacheStaticFiles(directory=STATIC_DIR), name="static") @app.get("/", include_in_schema=False) def index() -> HTMLResponse: - """前端 SPA 入口""" + """前端 SPA 入口 + + no-cache:HTML 必须每次回源校验,否则浏览器启发式缓存会持有旧 HTML, + 其中引用的 ?v= 静态资源版本号也是旧的,导致部署后用户看到旧版。 + """ html = jinja_env.get_template("index.html").render( app_name=settings.APP_NAME, asset_version=_asset_version(), app_version=APP_VERSION, git_commit=GIT_COMMIT, ) - return HTMLResponse(html) + return HTMLResponse(html, headers={"Cache-Control": "no-cache"}) @app.get("/sw.js", include_in_schema=False)