fix: 禁用静态文件缓存,添加版本号参数
This commit is contained in:
+6
-1
@@ -37,9 +37,14 @@ async def get_image(filename: str):
|
|||||||
@app.get("/", response_class=HTMLResponse)
|
@app.get("/", response_class=HTMLResponse)
|
||||||
async def index():
|
async def index():
|
||||||
"""主页"""
|
"""主页"""
|
||||||
|
# 添加时间戳参数防止缓存
|
||||||
index_file = STATIC_DIR / "index.html"
|
index_file = STATIC_DIR / "index.html"
|
||||||
if index_file.exists():
|
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>")
|
return HTMLResponse("<h1>请创建 index.html</h1>")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user