fix(cache): 入口HTML加no-cache,杜绝启发式缓存持有旧?v=版本号导致部署后看到旧版

This commit is contained in:
gouki
2026-08-08 23:42:40 +00:00
parent 6829b211ac
commit 74f9688ba1
2 changed files with 7 additions and 3 deletions
+6 -2
View File
@@ -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)