fix: 禁用静态文件缓存,添加版本号参数

This commit is contained in:
2026-04-16 11:01:51 +08:00
parent c69a912229
commit c4bfa5979c

View File

@@ -37,9 +37,14 @@ async def get_image(filename: str):
@app.get("/", response_class=HTMLResponse)
async def index():
"""主页"""
# 添加时间戳参数防止缓存
index_file = STATIC_DIR / "index.html"
if index_file.exists():
return FileResponse(str(index_file))
content = index_file.read_text(encoding='utf-8')
# 在引用静态文件时添加版本参数
content = content.replace('/static/style.css', '/static/style.css?v=1.1')
content = content.replace('/static/app.js', '/static/app.js?v=1.1')
return HTMLResponse(content=content)
return HTMLResponse("<h1>请创建 index.html</h1>")