diff --git a/dev/scripts/dossier_page/build.py b/dev/scripts/dossier_page/build.py index 3b58e5b..26a255b 100644 --- a/dev/scripts/dossier_page/build.py +++ b/dev/scripts/dossier_page/build.py @@ -22,9 +22,11 @@ so it follows them on every rebuild. The page inlines assets/css/fhirworx.css the favicon set (assets/icons). The template uses only those tokens. Cache: ``/*__VERSION__*/`` is the first 12 hex digits of a sha256 over the -sorted (name, bytes) of the ``*.js`` modules, stamped on the entry script -(``app.js?v=…``), so a new module set is a new URL; the modules it imports -revalidate through the ``dossier-nocache`` middleware. +sorted (name, bytes) of the ``*.js`` modules, plus ``CACHE_EPOCH``, stamped +on the entry script (``app.js?v=…``). The query string is the cache key. +``CACHE_EPOCH`` moved the key off a URL whose cached body was ``index.html`` +(the lex catch-all rewrote every path there). Imported modules are not +stored: ``dossier-nocache`` sends ``Cache-Control: no-store``. """ from __future__ import annotations @@ -107,12 +109,19 @@ def _fill(tpl: str, marker: str, value: str, count: int = 1) -> str: return tpl.replace(marker, value) +# Bumped so browsers drop app.js?v=ee6ab2354fa3. That URL was cached as the +# HTML page while lex-page rewrote every path to index.html, and a reload +# kept using it without asking the server again. +CACHE_EPOCH = b"lex-assets\n" + + def module_version(directory: Path) -> str: - """sha256 over the sorted (name, bytes) of the directory's ``*.js``, [:12].""" + """sha256 over CACHE_EPOCH and the sorted (name, bytes) of ``*.js``, [:12].""" files = sorted(p for p in Path(directory).glob("*.js") if p.is_file()) if not files: raise SystemExit(f"{directory}: no *.js modules") h = hashlib.sha256() + h.update(CACHE_EPOCH) for p in files: data = p.read_bytes() name = p.name.encode() diff --git a/infra/traefik/dynamic/services.yml b/infra/traefik/dynamic/services.yml index e0a2b91..14548af 100644 --- a/infra/traefik/dynamic/services.yml +++ b/infra/traefik/dynamic/services.yml @@ -63,11 +63,13 @@ http: rewrites: - regex: "" replacement: '' - # Gitea caches /assets/ for 6 h; the dossier page is rebuilt in place. + # Gitea sends public, max-age=21600 on /assets/. Replace it. A module + # URL once cached index.html under that lifetime, and reloads kept the + # cached body without asking again. dossier-nocache: headers: customResponseHeaders: - Cache-Control: "no-cache" + Cache-Control: "no-store" # lex. catch-all. Paths that are not a dossier module, the policy # API, or the focus pane become the static page. lex-assets is a # higher-priority router and must not use this middleware: the rewrite