From fe598cf3a431948bd31d7b24325624c43e97a90b Mon Sep 17 00:00:00 2001 From: Zankaria Date: Sat, 24 Aug 2024 01:36:49 +0200 Subject: [PATCH] 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 | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/templates/main.js b/templates/main.js index 9273543a..266999e7 100755 --- a/templates/main.js +++ b/templates/main.js @@ -156,7 +156,14 @@ function changeStyle(styleName, link) { this.media = 'all'; mainStylesheetElement.media = 'none'; } - document.getElementById('stylesheet').href = styles[styleName]; + + let style = styles[styleName]; + if (style !== '') { + // Add the version of the resource if the style is not the embedded one. + style = style + '?v=' + resourceVersion; + } + + document.getElementById('stylesheet').href = style; selectedstyle = styleName; if (codestyles[styleName]) { @@ -571,6 +578,7 @@ function ready() { var post_date = "{{ config.post_date }}"; var max_images = {{ config.max_images }}; +var resourceVersion = document.currentScript.getAttribute('data-resource-version'); onReady(init);