From 5f83d94119e87376641f12b1eb2a5ad02f1405fc Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Tue, 26 May 2026 00:14:15 -0700 Subject: [PATCH] Add content hash to JS includes (closes #2714) The CSS link in base.html already carries `?{{ app_css_hash }}` so that browsers refetch when the bundled file changes. The five first-party JS files shipped with datasette did not. Cache-busting JS the same way matches the existing CSS pattern and uses the static_hash() helper that already powers app_css_hash(). Files updated: - datasette/app.py: expose static_hash as a callable in template context. - datasette/handle_exception.py: include static_hash in the error-page template context (mirrors the existing app_css_hash entry there). - datasette/templates/base.html: hash datasette-manager.js and navigation-search.js. - datasette/templates/table.html: hash column-chooser.js, table.js, and mobile-column-actions.js. - tests/test_html.py: new test_js_content_hash parametrized across all five files; existing test_navigation_menu_links updated to expect the new query string. Vendored libraries (cm-editor-6.0.1.bundle.js, sql-formatter-2.3.3.min.js, json-format-highlight-1.0.1.js) already carry a version in the filename and were left unchanged. --- datasette/app.py | 1 + datasette/handle_exception.py | 1 + datasette/templates/base.html | 4 ++-- datasette/templates/table.html | 6 +++--- tests/test_html.py | 24 +++++++++++++++++++++++- 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/datasette/app.py b/datasette/app.py index 75f05d88..fab89da1 100644 --- a/datasette/app.py +++ b/datasette/app.py @@ -2052,6 +2052,7 @@ class Datasette: and "ds_actor" in request.cookies and request.actor, "app_css_hash": self.app_css_hash(), + "static_hash": self.static_hash, "zip": zip, "body_scripts": body_scripts, "format_bytes": format_bytes, diff --git a/datasette/handle_exception.py b/datasette/handle_exception.py index 96398a4c..3c78e6fd 100644 --- a/datasette/handle_exception.py +++ b/datasette/handle_exception.py @@ -67,6 +67,7 @@ def handle_exception(datasette, request, exception): info, urls=datasette.urls, app_css_hash=datasette.app_css_hash(), + static_hash=datasette.static_hash, menu_links=lambda: [], ) ), diff --git a/datasette/templates/base.html b/datasette/templates/base.html index e1767deb..23814d6a 100644 --- a/datasette/templates/base.html +++ b/datasette/templates/base.html @@ -8,7 +8,7 @@ {% endfor %} - + {% for url in extra_js_urls %} {% endfor %} @@ -70,7 +70,7 @@ {% endfor %} {% if select_templates %}{% endif %} - + diff --git a/datasette/templates/table.html b/datasette/templates/table.html index c841e1be..e5dd5ded 100644 --- a/datasette/templates/table.html +++ b/datasette/templates/table.html @@ -4,9 +4,9 @@ {% block extra_head %} {{- super() -}} - - - + + +