DecisionLab / app /assets.py
RealFalconsAI's picture
Upload 39 files
66ee87e verified
Raw History Blame Contribute Delete
591 Bytes
"""Release-stamped asset URLs for the page.
Every /static/... URL in index.html gets ?v=<release>, so each release has its own addresses and a browser can
never run a stale app.js or app.css cached from an older release (1.8.x files were served without cache headers).
Pure Python: tested anywhere.
"""
from __future__ import annotations
import re
_ASSET = re.compile(r'(["\'])(/static/[^"\'?#]+)\1')
def stamp_assets(html: str, version: str) -> str:
v = re.sub(r"[^A-Za-z0-9._-]+", "-", version)
return _ASSET.sub(lambda m: f"{m.group(1)}{m.group(2)}?v={v}{m.group(1)}", html)