From c2681ccc8613a156c4a4380f56eadb530a0fa1e3 Mon Sep 17 00:00:00 2001 From: Petr Date: Thu, 12 Mar 2026 15:37:29 +0100 Subject: [PATCH] Add cache-busting with git commit hash for static assets Flask will now include git commit hash as URL parameter (v=abc1234) for metric_modal.js and other static assets. This ensures browser doesn't cache stale JavaScript when code changes. Cache invalidation based on actual git history rather than timestamps. --- webapp/app.py | 19 +++++++++++++++++++ webapp/templates/catalog.html | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/webapp/app.py b/webapp/app.py index 1f228a5..b6ae908 100644 --- a/webapp/app.py +++ b/webapp/app.py @@ -73,6 +73,24 @@ logger = logging.getLogger(__name__) _catalog_enricher = None +def get_git_commit_hash() -> str: + """Get current git commit hash for cache busting static assets.""" + try: + import subprocess + result = subprocess.run( + ['git', 'rev-parse', '--short', 'HEAD'], + cwd=Path(__file__).parent.parent, + capture_output=True, + text=True, + timeout=2 + ) + if result.returncode == 0: + return result.stdout.strip() + except Exception: + pass + return "dev" + + def create_app() -> Flask: """Create and configure the Flask application.""" global _catalog_enricher @@ -894,6 +912,7 @@ def register_routes(app: Flask) -> None: catalog_data=catalog_data, sync_settings=sync_settings, metrics_data=metrics_data, + git_version=get_git_commit_hash(), ) @app.route("/api/catalog/profile/") diff --git a/webapp/templates/catalog.html b/webapp/templates/catalog.html index 13e8a2e..62ff716 100644 --- a/webapp/templates/catalog.html +++ b/webapp/templates/catalog.html @@ -2410,7 +2410,7 @@ document.addEventListener('keydown', e => { - +