From 6d1b1df1aa79e3446656254722c204cb9fd40022 Mon Sep 17 00:00:00 2001 From: dakkar Date: Wed, 19 Jun 2024 15:46:57 +0100 Subject: [PATCH] cache-bursting for stylesheets and fonts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit adding `?version=…` makes sure browsers get the latest files, and it looks like they honour the caching headers we send back --- packages/backend/src/server/web/views/base.pug | 4 ++-- scripts/build-assets.mjs | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/server/web/views/base.pug b/packages/backend/src/server/web/views/base.pug index c1e38717c..400763229 100644 --- a/packages/backend/src/server/web/views/base.pug +++ b/packages/backend/src/server/web/views/base.pug @@ -40,8 +40,8 @@ html link(rel='prefetch' href=infoImageUrl) link(rel='prefetch' href=notFoundImageUrl) //- https://github.com/misskey-dev/misskey/issues/9842 - link(rel='stylesheet' href='/assets/phosphor-icons/bold/style.css') - link(rel='stylesheet' href='/static-assets/fonts/sharkey-icons/style.css') + link(rel='stylesheet' href=`/assets/phosphor-icons/bold/style.css?version=${version}`) + link(rel='stylesheet' href=`/static-assets/fonts/sharkey-icons/style.css?version=${version}`) link(rel='modulepreload' href=`/vite/${clientEntry.file}`) if !config.clientManifestExists diff --git a/scripts/build-assets.mjs b/scripts/build-assets.mjs index 7d0ab2fc8..c3c38cd9a 100644 --- a/scripts/build-assets.mjs +++ b/scripts/build-assets.mjs @@ -35,6 +35,20 @@ async function copyFrontendFonts() { async function copyFrontendTablerIcons() { await fs.cp('./packages/frontend/node_modules/@phosphor-icons/web/src', './built/_frontend_dist_/phosphor-icons', { dereference: true, recursive: true }); + + for (const file of [ + './built/_frontend_dist_/phosphor-icons/bold/style.css', + './built/_frontend_dist_/phosphor-icons/duotone/style.css', + './built/_frontend_dist_/phosphor-icons/fill/style.css', + './built/_frontend_dist_/phosphor-icons/light/style.css', + './built/_frontend_dist_/phosphor-icons/regular/style.css', + './built/_frontend_dist_/phosphor-icons/thin/style.css', + ]) { + let source = await fs.readFile(file, { encoding: 'utf-8' }); + source = source.replaceAll(/(url\(.+?Phosphor.+?\.(?:[a-zA-Z0-9]+))/g, `$1?version=${meta.version}`); + await fs.writeFile(file, source); + } + } async function copyFrontendLocales() {