Cache-busting des assets statiques

Le navigateur servait un CSS périmé après mise à jour (aucun invalidateur
sur /static). Les liens CSS/JS portent désormais ?v=<mtime des fichiers
statiques> : toute modification du design est visible immédiatement chez
tous les clients, sans hard-refresh ni bump manuel de version.
This commit is contained in:
Roman
2026-09-25 14:58:42 +00:00
parent d747c574b8
commit c45f1b79fd
3 changed files with 11 additions and 4 deletions
+7
View File
@@ -12,6 +12,13 @@ protected = APIRouter(tags=["pages"], include_in_schema=False, dependencies=[Dep
templates = Jinja2Templates(directory=BASE_DIR / "app" / "templates")
# Cache-busting des assets : version dérivée de la date des fichiers statiques —
# tout changement de CSS/JS invalide le cache navigateur sans intervention.
_static_root = BASE_DIR / "app" / "static"
templates.env.globals["asset_v"] = str(
max(int(p.stat().st_mtime) for p in _static_root.rglob("*") if p.is_file())
)
@router.get("/login", response_class=HTMLResponse)
async def login_page(request: Request) -> HTMLResponse:
+3 -3
View File
@@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% block title %}Ohm Stream{% endblock %}</title>
<link rel="stylesheet" href="/static/css/style.css">
<link rel="stylesheet" href="/static/css/style.css?v={{ asset_v }}">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700;800&display=swap" rel="stylesheet">
<script src="https://unpkg.com/htmx.org@2.0.4"></script>
@@ -37,8 +37,8 @@
<main class="main">
{% block content %}{% endblock %}
</main>
<script src="/static/js/app.js"></script>
<script src="/static/js/update-watcher.js"></script>
<script src="/static/js/app.js?v={{ asset_v }}"></script>
<script src="/static/js/update-watcher.js?v={{ asset_v }}"></script>
{% block scripts %}{% endblock %}
</body>
</html>
+1 -1
View File
@@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Connexion — Ohm Stream</title>
<link rel="stylesheet" href="/static/css/style.css">
<link rel="stylesheet" href="/static/css/style.css?v={{ asset_v }}">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.14.1/dist/cdn.min.js"></script>
</head>