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.
This commit is contained in:
parent
f6000cc867
commit
c2681ccc86
2 changed files with 20 additions and 1 deletions
|
|
@ -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/<table_name>")
|
||||
|
|
|
|||
|
|
@ -2410,7 +2410,7 @@ document.addEventListener('keydown', e => {
|
|||
<!-- Prism.js for SQL syntax highlighting -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/prism.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/components/prism-sql.min.js"></script>
|
||||
<script src="{{ url_for('static', filename='js/metric_modal.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='js/metric_modal.js', v=git_version) }}"></script>
|
||||
|
||||
<!-- Mermaid.js for relationship diagrams -->
|
||||
<script type="module">
|
||||
|
|
|
|||
Loading…
Reference in a new issue