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.
pull/3899/head^2
Sebastian Castro 2020-04-28 17:22:26 +02:00 committed by muxator
parent fda0d2884e
commit 95fd5ce2a4
4 changed files with 40 additions and 26 deletions

View File

@ -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
*/

View File

@ -35,8 +35,8 @@
<link rel="shortcut icon" href="<%=settings.favicon%>">
<link rel="localizations" type="application/l10n+json" href="locales.json">
<script type="text/javascript" src="static/js/html10n.js"></script>
<script type="text/javascript" src="static/js/l10n.js"></script>
<script type="text/javascript" src="static/js/html10n.js?v=<%=settings.randomVersionString%>"></script>
<script type="text/javascript" src="static/js/l10n.js?v=<%=settings.randomVersionString%>"></script>
<style>
html, body {
@ -156,7 +156,7 @@
}
}
</style>
<link href="static/skins/<%=encodeURI(settings.skinName)%>/index.css" rel="stylesheet">
<link href="static/skins/<%=encodeURI(settings.skinName)%>/index.css?v=<%=settings.randomVersionString%>" rel="stylesheet">
<div id="wrapper">
<% e.begin_block("indexWrapper"); %>
@ -171,7 +171,7 @@
<% e.end_block(); %>
</div>
<script src="static/skins/<%=encodeURI(settings.skinName)%>/index.js"></script>
<script src="static/skins/<%=encodeURI(settings.skinName)%>/index.js?v=<%=settings.randomVersionString%>"></script>
<script>
// @license magnet:?xt=urn:btih:8e4f440f4c65981c5bf93c76d35135ba5064d8b7&dn=apache-2.0.txt
function go2Name()

View File

@ -42,18 +42,18 @@
<link rel="shortcut icon" href="<%=settings.faviconPad%>">
<% e.begin_block("styles"); %>
<link href="../static/css/pad.css" rel="stylesheet">
<link href="../static/css/pad.css?v=<%=settings.randomVersionString%>" rel="stylesheet">
<% e.begin_block("customStyles"); %>
<link href="../static/skins/<%=encodeURI(settings.skinName)%>/pad.css" rel="stylesheet">
<link href="../static/skins/<%=encodeURI(settings.skinName)%>/pad.css?v=<%=settings.randomVersionString%>" rel="stylesheet">
<% e.end_block(); %>
<style title="dynamicsyntax"></style>
<% e.end_block(); %>
<link rel="localizations" type="application/l10n+json" href="../locales.json" />
<script type="text/javascript" src="../static/js/html10n.js"></script>
<script type="text/javascript" src="../static/js/l10n.js"></script>
<script type="text/javascript" src="../static/js/html10n.js?v=<%=settings.randomVersionString%>"></script>
<script type="text/javascript" src="../static/js/l10n.js?v=<%=settings.randomVersionString%>"></script>
<!-- head and body had been removed intentionally -->
@ -435,10 +435,10 @@
<% e.begin_block("scripts"); %>
<script type="text/javascript" src="../static/js/require-kernel.js"></script>
<script type="text/javascript" src="../static/js/require-kernel.js?v=<%=settings.randomVersionString%>"></script>
<!-- Include pad_utils manually -->
<script type="text/javascript" src="../javascripts/lib/ep_etherpad-lite/static/js/pad_utils.js?callback=require.define"></script>
<script type="text/javascript" src="../javascripts/lib/ep_etherpad-lite/static/js/pad_utils.js?callback=require.define&v=<%=settings.randomVersionString%>"></script>
<script type="text/javascript">
// @license magnet:?xt=urn:btih:8e4f440f4c65981c5bf93c76d35135ba5064d8b7&dn=apache-2.0.txt
@ -458,14 +458,14 @@
// @license-end
</script>
<script type="text/javascript" src="../socket.io/socket.io.js"></script>
<script type="text/javascript" src="../socket.io/socket.io.js?v=<%=settings.randomVersionString%>"></script>
<!-- Include base packages manually (this help with debugging) -->
<script type="text/javascript" src="../javascripts/lib/ep_etherpad-lite/static/js/pad.js?callback=require.define"></script>
<script type="text/javascript" src="../javascripts/lib/ep_etherpad-lite/static/js/ace2_common.js?callback=require.define"></script>
<script type="text/javascript" src="../javascripts/lib/ep_etherpad-lite/static/js/pad.js?callback=require.define&v=<%=settings.randomVersionString%>"></script>
<script type="text/javascript" src="../javascripts/lib/ep_etherpad-lite/static/js/ace2_common.js?callback=require.define&v=<%=settings.randomVersionString%>"></script>
<% e.begin_block("customScripts"); %>
<script type="text/javascript" src="../static/skins/<%=encodeURI(settings.skinName)%>/pad.js"></script>
<script type="text/javascript" src="../static/skins/<%=encodeURI(settings.skinName)%>/pad.js?v=<%=settings.randomVersionString%>"></script>
<% e.end_block(); %>
<!-- Bootstrap page -->

View File

@ -35,18 +35,18 @@
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<link rel="shortcut icon" href="<%=settings.faviconTimeslider%>">
<% e.begin_block("timesliderStyles"); %>
<link rel="stylesheet" href="../../static/css/pad.css">
<link rel="stylesheet" href="../../static/css/iframe_editor.css">
<link rel="stylesheet" href="../../static/css/timeslider.css">
<link rel="stylesheet" href="../../static/skins/<%=encodeURI(settings.skinName)%>/pad.css">
<link rel="stylesheet" href="../../static/skins/<%=encodeURI(settings.skinName)%>/timeslider.css">
<link rel="stylesheet" href="../../static/css/pad.css?v=<%=settings.randomVersionString%>">
<link rel="stylesheet" href="../../static/css/iframe_editor.css?v=<%=settings.randomVersionString%>">
<link rel="stylesheet" href="../../static/css/timeslider.css?v=<%=settings.randomVersionString%>">
<link rel="stylesheet" href="../../static/skins/<%=encodeURI(settings.skinName)%>/pad.css?v=<%=settings.randomVersionString%>">
<link rel="stylesheet" href="../../static/skins/<%=encodeURI(settings.skinName)%>/timeslider.css?v=<%=settings.randomVersionString%>">
<style type="text/css" title="dynamicsyntax"></style>
<% e.end_block(); %>
<link rel="localizations" type="application/l10n+json" href="../../locales.json" />
<% e.begin_block("timesliderScripts"); %>
<script type="text/javascript" src="../../static/js/html10n.js"></script>
<script type="text/javascript" src="../../static/js/l10n.js"></script>
<script type="text/javascript" src="../../static/js/html10n.js?v=<%=settings.randomVersionString%>"></script>
<script type="text/javascript" src="../../static/js/l10n.js?v=<%=settings.randomVersionString%>"></script>
<% e.end_block(); %>
</head>
@ -245,14 +245,14 @@
<!-------- JAVASCRIPT --------->
<!----------------------------->
<script type="text/javascript" src="../../static/js/require-kernel.js"></script>
<script type="text/javascript" src="../../socket.io/socket.io.js"></script>
<script type="text/javascript" src="../../static/js/require-kernel.js?v=<%=settings.randomVersionString%>"></script>
<script type="text/javascript" src="../../socket.io/socket.io.js?v=<%=settings.randomVersionString%>"></script>
<!-- Include base packages manually (this help with debugging) -->
<script type="text/javascript" src="../../javascripts/lib/ep_etherpad-lite/static/js/timeslider.js?callback=require.define"></script>
<script type="text/javascript" src="../../javascripts/lib/ep_etherpad-lite/static/js/ace2_common.js?callback=require.define"></script>
<script type="text/javascript" src="../../javascripts/lib/ep_etherpad-lite/static/js/timeslider.js?callback=require.define&v=<%=settings.randomVersionString%>"></script>
<script type="text/javascript" src="../../javascripts/lib/ep_etherpad-lite/static/js/ace2_common.js?callback=require.define&v=<%=settings.randomVersionString%>"></script>
<script type="text/javascript" src="../../static/skins/<%=encodeURI(settings.skinName)%>/timeslider.js"></script>
<script type="text/javascript" src="../../static/skins/<%=encodeURI(settings.skinName)%>/timeslider.js?v=<%=settings.randomVersionString%>"></script>
<!-- Bootstrap -->
<script type="text/javascript" >