DNS: cache-bust dns.js (DNS_STATIC_VERSION), no-cache headers on CloudFlare page

This commit is contained in:
master3395
2026-02-16 18:09:58 +01:00
parent 08472ae012
commit ae6289ef9c
4 changed files with 33 additions and 2 deletions

View File

@@ -77,4 +77,29 @@ def firewall_static_context(request):
version = int(time.time())
return {
'FIREWALL_STATIC_VERSION': version
}
def dns_static_context(request):
"""Cache-busting for DNS static assets (bumps when dns.js changes). Avoids stale JS/layout."""
try:
from django.conf import settings
base = settings.BASE_DIR
paths = [
os.path.join(base, 'dns', 'static', 'dns', 'dns.js'),
os.path.join(base, 'static', 'dns', 'dns.js'),
os.path.join(base, 'public', 'static', 'dns', 'dns.js'),
]
version = 0
for p in paths:
try:
version = max(version, int(os.path.getmtime(p)))
except (OSError, TypeError):
pass
if version <= 0:
version = int(time.time())
except (OSError, AttributeError):
version = int(time.time())
return {
'DNS_STATIC_VERSION': version
}