Spaces:
Running on Zero
Running on Zero
File size: 591 Bytes
66ee87e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | """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)
|