diff --git a/evennia/web/templates/webclient/base.html b/evennia/web/templates/webclient/base.html index a76c45f801..780d32bee1 100644 --- a/evennia/web/templates/webclient/base.html +++ b/evennia/web/templates/webclient/base.html @@ -6,7 +6,7 @@ with evennia set up automatically and get the Evennia JS lib and JQuery available. --> -{% load static %} +{% load static cachebuster %} {{game_name}} @@ -17,13 +17,13 @@ JQuery available. - + {% comment %} Allows for loading custom styles without overriding the base site stylesheet {% endcomment %} - + @@ -76,7 +76,7 @@ JQuery available. var wsurl = "ws://" + this.location.hostname + ":{{websocket_port}}"; {% endif %} - + - + {% comment %} Allows for loading custom styles without overriding the base site styles {% endcomment %} - + {% block header_ext %} {% endblock %} diff --git a/evennia/web/templatetags/cachebuster.py b/evennia/web/templatetags/cachebuster.py new file mode 100644 index 0000000000..304a27f6cb --- /dev/null +++ b/evennia/web/templatetags/cachebuster.py @@ -0,0 +1,16 @@ +from django import template +from django.conf import settings +from django.contrib.staticfiles import finders + +register = template.Library() + +@register.filter +def cachebust(value, digest_size=5): + filepath = finders.find(value.removeprefix(settings.STATIC_URL)) + if not filepath: + return value + + with open(filepath, "rb") as f: + import hashlib + filehash = hashlib.shake_256(f.read()).hexdigest(digest_size) + return f"{value}?{filehash}"