Skip to content

Commit

Permalink
Invalidate browser cache after new version release
Browse files Browse the repository at this point in the history
  • Loading branch information
refi93 committed Sep 24, 2021
1 parent 38058a9 commit 2f10340
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
6 changes: 5 additions & 1 deletion app/public/js/init.js
Expand Up @@ -50,9 +50,13 @@ function playsNice(cb) {
function loadScript(success) {
if (success) {
// if everything goes well, load the main script
const appVersion = JSON.parse(document.body.attributes['data-config'].textContent).ADALITE_APP_VERSION
const appVersionStr = appVersion.replaceAll('.', '-')

const mainScriptTag = document.createElement('script')
mainScriptTag.type = 'text/javascript'
mainScriptTag.src = 'js/frontend.bundle.js'
// adding appVersionStr for the sake of browser cache invalidation
mainScriptTag.src = `js/frontend.bundle.js?v=${appVersionStr}`
mainScriptTag.setAttribute('defer', '')
document.getElementsByTagName('head')[0].appendChild(mainScriptTag)
} else {
Expand Down
1 change: 1 addition & 0 deletions server/helpers/loadConfig.js
Expand Up @@ -183,6 +183,7 @@ const frontendConfig = {
const backendConfig = {
PORT,
REDIS_URL,
ADALITE_APP_VERSION: appVersion,
ADALITE_STATS_PWD,
ADALITE_TREZOR_CONNECT_URL,
ADALITE_ENABLE_SERVER_MOCKING_MODE,
Expand Down
21 changes: 13 additions & 8 deletions server/index.js
Expand Up @@ -89,6 +89,7 @@ require('./poolInfoGetter')(app)

app.get('*', (req, res) => {
const serverUrl = backendConfig.ADALITE_SERVER_URL
const appVersionStr = backendConfig.ADALITE_APP_VERSION.replaceAll('.', '-')
return res.status(200).send(`
<!doctype html>
<html>
Expand All @@ -115,15 +116,19 @@ app.get('*', (req, res) => {
<meta property="og:description" content="Free open-source web-browser Cardano wallet with Trezor and Ledger Nano S and Nano X support">
<meta property="og:image" content="${serverUrl}/assets/og-image.png">
<script src="js/init.js"></script>
<link rel="stylesheet" type="text/css" href="css/styles.css">
<link rel="stylesheet" type="text/css" href="css/0-767px.css">
<link rel="stylesheet" type="text/css" href="css/0-1366px.css">
<link rel="stylesheet" type="text/css" href="css/767-1366px.css">
<link rel="stylesheet" type="text/css" href="css/768-1024px.css">
<link rel="stylesheet" type="text/css" href="css/1024-1112px.css">
<script src="js/init.js?v=${appVersionStr}"></script>
<link rel="stylesheet" type="text/css" href="css/styles.css?v=${appVersionStr}">
<link rel="stylesheet" type="text/css" href="css/0-767px.css?v=${appVersionStr}">
<link rel="stylesheet" type="text/css" href="css/0-1366px.css?v=${appVersionStr}">
<link rel="stylesheet" type="text/css" href="css/767-1366px.css?v=${appVersionStr}">
<link rel="stylesheet" type="text/css" href="css/768-1024px.css?v=${appVersionStr}">
<link rel="stylesheet" type="text/css" href="css/1024-1112px.css?v=${appVersionStr}">
<link rel="icon" type="image/ico" href="assets/favicon.ico">
${isProd ? '<link rel="stylesheet" type="text/css" href="css/modules.css">' : ''}
${
isProd
? `<link rel="stylesheet" type="text/css" href="css/modules.css?v=${appVersionStr}">`
: ''
}
${
backendConfig.ADALITE_TREZOR_CONNECT_URL
? `<script src="${backendConfig.ADALITE_TREZOR_CONNECT_URL}"></script>`
Expand Down

0 comments on commit 2f10340

Please sign in to comment.