From 95fd5ce2a45e31980ad8c2562e3fe6f77c52d4ff Mon Sep 17 00:00:00 2001 From: Sebastian Castro Date: Tue, 28 Apr 2020 17:22:26 +0200 Subject: [PATCH] assets: add random string to query string to bust cache on restart and deploys After each Eterpad restart, the clients will request a new version of the static assets, even if they are not modified. This is the price we pay for knowing that no stale files are going to be served ever again. We could also have used a salted hash of the Etherpad version, but we chose the simpler way. For the rationale behind using a random string at each restart, see #3958. ACHTUNG: this may prevent caching HTTP proxies to work. Closes #3955. --- src/node/utils/Settings.js | 14 ++++++++++++++ src/templates/index.html | 8 ++++---- src/templates/pad.html | 20 ++++++++++---------- src/templates/timeslider.html | 24 ++++++++++++------------ 4 files changed, 40 insertions(+), 26 deletions(-) diff --git a/src/node/utils/Settings.js b/src/node/utils/Settings.js index 369a4485f..c8f2ec159 100644 --- a/src/node/utils/Settings.js +++ b/src/node/utils/Settings.js @@ -42,6 +42,20 @@ var _ = require("underscore"); exports.root = absolutePaths.findEtherpadRoot(); console.log(`All relative paths will be interpreted relative to the identified Etherpad base dir: ${exports.root}`); +/* + * At each start, Etherpad generates a random string and appends it as query + * parameter to the URLs of the static assets, in order to force their reload. + * Subsequent requests will be cached, as long as the server is not reloaded. + * + * For the rationale behind this choice, see + * https://github.com/ether/etherpad-lite/pull/3958 + * + * ACHTUNG: this may prevent caching HTTP proxies to work + * TODO: remove the "?v=randomstring" parameter, and replace with hashed filenames instead + */ +exports.randomVersionString = randomString(4); +console.log(`Random string used for versioning assets: ${exports.randomVersionString}`); + /** * The app title, visible e.g. in the browser window */ diff --git a/src/templates/index.html b/src/templates/index.html index 0e36f71cc..4fb810478 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -35,8 +35,8 @@ - - + + - +
<% e.begin_block("indexWrapper"); %> @@ -171,7 +171,7 @@ <% e.end_block(); %>
- + - + + @@ -435,10 +435,10 @@ <% e.begin_block("scripts"); %> - + - + - + - - + + <% e.begin_block("customScripts"); %> - + <% e.end_block(); %> diff --git a/src/templates/timeslider.html b/src/templates/timeslider.html index 2368f0ea1..5d826ceeb 100644 --- a/src/templates/timeslider.html +++ b/src/templates/timeslider.html @@ -35,18 +35,18 @@ <% e.begin_block("timesliderStyles"); %> - - - - - + + + + + <% e.end_block(); %> <% e.begin_block("timesliderScripts"); %> - - + + <% e.end_block(); %> @@ -245,14 +245,14 @@ - - + + - - + + - +