mobile: cache-bust static assets so browser picks up CSS/JS edits

User reported phone still showing old behaviour (Qty/Avg portfolio
columns visible) even though the server-side JS had been updated.
Root cause: every <link>/<script> URL was a plain
/static/css/foo.css with no query string, so mobile Chrome served
the file from its HTTP cache rather than refetching it.

Adds a process-startup timestamp to the Jinja environment as
ASSET_VERSION (computed once when templates_env is imported). Every
<link>/<script> reference now appends `?v={{ ASSET_VERSION }}` so a
container restart bumps the URL and the browser refetches. 38 URLs
across 8 templates updated via sed; tests still pass.

Side benefit: future CSS/JS edits no longer require users to hard-
refresh.
This commit is contained in:
Giorgio Gilestro 2026-05-28 19:20:49 +02:00
parent 1a20f0a15b
commit daa3f79a52
9 changed files with 47 additions and 38 deletions

View file

@ -3,6 +3,7 @@ Imported by both routers/pages.py and routers/api.py so the filters are
registered exactly once."""
from __future__ import annotations
import time
from pathlib import Path
from fastapi.templating import Jinja2Templates
@ -13,6 +14,13 @@ from app.config import get_settings
from app.services.glossary import wrap_glossary
# Cache-busting token for static assets. Computed once at import time
# (i.e. process startup), so every container restart yields a fresh
# value and browsers refetch CSS/JS instead of serving stale cache.
# Templates append `?v={{ ASSET_VERSION }}` to every static URL.
ASSET_VERSION = str(int(time.time()))
TEMPLATE_DIR = Path(__file__).resolve().parent / "templates"
@ -77,3 +85,4 @@ templates.env.globals["LEGAL_OPERATOR"] = branding.LEGAL_OPERATOR
templates.env.globals["OPERATOR_EMAIL"] = branding.OPERATOR_EMAIL
templates.env.globals["OPERATOR_JURISDICTION"] = branding.OPERATOR_JURISDICTION
templates.env.globals["BETA_MODE"] = get_settings().BETA_MODE
templates.env.globals["ASSET_VERSION"] = ASSET_VERSION