From 9bc3f885bc5ad9b4020e6008426fb4fdb056e06a Mon Sep 17 00:00:00 2001 From: yawhn Date: Wed, 2 Nov 2022 23:31:42 +0200 Subject: [PATCH] [#9064] Fix CSS and Image caching issue --- packages/backend/src/server/web/index.ts | 2 ++ packages/backend/src/server/web/views/base.pug | 15 +++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/backend/src/server/web/index.ts b/packages/backend/src/server/web/index.ts index c81506384c..4ede90ff95 100644 --- a/packages/backend/src/server/web/index.ts +++ b/packages/backend/src/server/web/index.ts @@ -526,6 +526,7 @@ router.get('(.*)', async ctx => { if (meta.customSplashIcons.length > 0) { splashIconUrl = meta.customSplashIcons[Math.floor(Math.random() * meta.customSplashIcons.length)]; } + const nowDateMs = Date.now(); await ctx.render('base', { img: meta.bannerUrl, title: meta.name || 'Calckey', @@ -536,6 +537,7 @@ router.get('(.*)', async ctx => { themeColor: meta.themeColor, randomMOTD: motd[Math.floor(Math.random() * motd.length)], privateMode: meta.privateMode, + nowDateMs: nowDateMs, }); ctx.set('Cache-Control', 'public, max-age=3'); }); diff --git a/packages/backend/src/server/web/views/base.pug b/packages/backend/src/server/web/views/base.pug index 8b4d41e123..f06f2cab2d 100644 --- a/packages/backend/src/server/web/views/base.pug +++ b/packages/backend/src/server/web/views/base.pug @@ -29,15 +29,14 @@ html meta(property='twitter:card' content='summary') meta(property='og:site_name' content= instanceName || 'Calckey') meta(name='viewport' content='width=device-width, initial-scale=1') - meta(name='darkreader-lock') - link(rel='icon' href= icon || '/favicon.ico') - link(rel='apple-touch-icon' href= icon || '/apple-touch-icon.png') + link(rel='icon' href= icon || `/favicon.ico?${ nowDateMs }`) + link(rel='apple-touch-icon' href= icon || `/apple-touch-icon.png?${ nowDateMs }`) link(rel='manifest' href='/manifest.json') - link(rel='prefetch' href='/static-assets/badges/info.png') - link(rel='prefetch' href='/static-assets/badges/not-found.png') - link(rel='prefetch' href='/static-assets/badges/error.png') + link(rel='prefetch' href=`/static-assets/badges/info.png?${ nowDateMs }`) + link(rel='prefetch' href=`/static-assets/badges/not-found.png?${ nowDateMs }`) + link(rel='prefetch' href=`/static-assets/badges/error.png?${ nowDateMs }`) link(rel='stylesheet' href='/assets/fontawesome/css/all.css') - link(rel='stylesheet' href='/static-assets/instance.css') + link(rel='stylesheet' href=`/static-assets/instance.css?${ nowDateMs }`) link(rel='modulepreload' href=`/assets/${clientEntry.file}`) each href in clientEntry.css @@ -78,7 +77,7 @@ html br | Please turn on your JavaScript div#splash - img#splashIcon(src= splashIcon || '/static-assets/splash.png') + img#splashIcon(src= splashIcon || `/static-assets/splash.png?${ nowDateMs }`) span#splashText block randomMOTD = randomMOTD