From 9fbc816205af457773b0f42ea18f6fb9605885be Mon Sep 17 00:00:00 2001 From: Zankaria Date: Thu, 22 Aug 2024 00:09:28 +0200 Subject: [PATCH 1/4] templates: bust all js caches with resource_version --- templates/header.html | 2 +- templates/mod/ban_list.html | 12 ++++++------ templates/mod/pages.html | 4 ++-- templates/mod/recent_posts.html | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/templates/header.html b/templates/header.html index b2c0f054..b928ff4a 100644 --- a/templates/header.html +++ b/templates/header.html @@ -17,7 +17,7 @@ {% for javascript in config.additional_javascript %}{% endfor %} {% endif %} {% if mod %} - + {% endif %} {% endif %} {% if config.captcha.provider == 'recaptcha' %} diff --git a/templates/mod/ban_list.html b/templates/mod/ban_list.html index f039350b..4a4586f7 100644 --- a/templates/mod/ban_list.html +++ b/templates/mod/ban_list.html @@ -1,9 +1,9 @@ - - - - - + + + + + @@ -32,7 +32,7 @@ - + {% if token_json %} diff --git a/templates/mod/pages.html b/templates/mod/pages.html index c2395c02..f6be9487 100644 --- a/templates/mod/pages.html +++ b/templates/mod/pages.html @@ -1,4 +1,4 @@ - +

{% if board %} @@ -27,7 +27,7 @@ -
{% trans %}URL{% endtrans %}{% trans %}Title{% endtrans %}
+ diff --git a/templates/mod/recent_posts.html b/templates/mod/recent_posts.html index d5e5d83c..55f854b5 100644 --- a/templates/mod/recent_posts.html +++ b/templates/mod/recent_posts.html @@ -1,4 +1,4 @@ - + {% if not posts|length %}

({% trans 'There are no active posts.' %})

{% else %} From fcf5c3d73afaddc24197b2353718be18f0bb462a Mon Sep 17 00:00:00 2001 From: Zankaria Date: Thu, 22 Aug 2024 00:15:51 +0200 Subject: [PATCH 2/4] templates: bust all css caches with resource_version --- templates/header.html | 6 +++--- templates/mod/ban_list.html | 4 ++-- templates/themes/recent/recent.html | 16 ++++++++-------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/templates/header.html b/templates/header.html index b928ff4a..335f572e 100644 --- a/templates/header.html +++ b/templates/header.html @@ -3,9 +3,9 @@ {% if config.meta_keywords %}{% endif %} -{% if config.default_stylesheet.1 != '' %}{% endif %} -{% if config.font_awesome %}{% endif %} -{% if config.country_flags_condensed %}{% endif %} +{% if config.default_stylesheet.1 != '' %}{% endif %} +{% if config.font_awesome %}{% endif %} +{% if config.country_flags_condensed %}{% endif %} - - + +
{% if token %} diff --git a/templates/themes/recent/recent.html b/templates/themes/recent/recent.html index 2a4510f8..9fce7ab8 100644 --- a/templates/themes/recent/recent.html +++ b/templates/themes/recent/recent.html @@ -4,11 +4,11 @@ {{ settings.title }} - - + + {% if config.url_favicon %}{% endif %} - {% if config.default_stylesheet.1 != '' %}{% endif %} - {% if config.font_awesome %}{% endif %} + {% if config.default_stylesheet.1 != '' %}{% endif %} + {% if config.font_awesome %}{% endif %} {% include 'header.html' %} @@ -17,7 +17,7 @@

{{ settings.title }}

{{ settings.subtitle }}
- +

Recent Images

@@ -36,7 +36,7 @@
    {% for post in recent_posts %}
  • - {{ post.board_name }}: + {{ post.board_name }}: {{ post.snippet }} @@ -53,11 +53,11 @@
- +
{% include 'footer.html' %} - + {% endapply %} From 3c5484a7c273aaffdf025fc293383ce5f960d3d0 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Sat, 24 Aug 2024 01:36:49 +0200 Subject: [PATCH 3/4] main.js: load styles with dyanamically provided resource version. This is done because: - If the version is updated before the rebuild, someone might cache the old version in the meanwhile. - One could not rebuild javascript before updating the version. Now it's possible. --- templates/main.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/templates/main.js b/templates/main.js index 13c80c33..82c87094 100644 --- a/templates/main.js +++ b/templates/main.js @@ -141,7 +141,33 @@ function changeStyle(styleName, link) { x.appendChild(s); } - document.getElementById('stylesheet').href = styles[styleName]; + let mainStylesheetElement = document.getElementById('stylesheet'); + let userStylesheetElement = document.getElementById('stylesheet-user'); + + // Override main stylesheet with the user selected one. + if (!userStylesheetElement) { + userStylesheetElement = document.createElement('link'); + userStylesheetElement.rel = 'stylesheet'; + userStylesheetElement.media = 'none'; + userStylesheetElement.type = 'text/css'; + userStylesheetElement.id = 'stylesheet'; + let x = document.getElementsByTagName('head')[0]; + x.appendChild(userStylesheetElement); + } + + // When the new one is loaded, disable the old one + userStylesheetElement.onload = function() { + this.media = 'all'; + mainStylesheetElement.media = 'none'; + } + + let style = styles[styleName]; + if (style !== '') { + // Add the version of the resource if the style is not the embedded one. + style += `?v=${resourceVersion}`; + } + + document.getElementById('stylesheet').href = style; selectedstyle = styleName; if (document.getElementsByClassName('styles').length != 0) { @@ -162,6 +188,7 @@ function changeStyle(styleName, link) { {% endverbatim %} +var resourceVersion = document.currentScript.getAttribute('data-resource-version'); {% if config.stylesheets_board %} {% verbatim %} From 6b60f841d4cde117431cd285644d896866af2568 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Sat, 24 Aug 2024 01:43:31 +0200 Subject: [PATCH 4/4] template: supply data-resource-version to main.js --- templates/header.html | 2 +- templates/mod/ban_list.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/header.html b/templates/header.html index 335f572e..51a9593c 100644 --- a/templates/header.html +++ b/templates/header.html @@ -12,7 +12,7 @@ var modRoot = "{{ config.root }}" + (inMod ? "mod.php?/" : ""); {% if not nojavascript %} - + {% if not config.additional_javascript_compile %} {% for javascript in config.additional_javascript %}{% endfor %} {% endif %} diff --git a/templates/mod/ban_list.html b/templates/mod/ban_list.html index 9115ddb3..ee8753f7 100644 --- a/templates/mod/ban_list.html +++ b/templates/mod/ban_list.html @@ -1,4 +1,4 @@ - +