From d4dc124e9986d18096d54ec6f2b4b283de1536cc Mon Sep 17 00:00:00 2001 From: Aaron Liu <912394456@qq.com> Date: Wed, 8 Feb 2023 13:53:48 +0800 Subject: [PATCH] fix(i18n): disable cache by appending version numbers --- config/webpack.config.js | 6 ++++++ src/component/Setting/WebDAV.js | 4 +++- src/i18n.ts | 3 +++ src/utils/index.js | 7 ++----- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/config/webpack.config.js b/config/webpack.config.js index b4313d4..02f8232 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -648,6 +648,12 @@ module.exports = function(webpackEnv) { // https://github.com/jmblog/how-to-optimize-momentjs-with-webpack // You can remove this if you don't use Moment.js: new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/), + + new webpack.DefinePlugin({ + ASSETS_VERSION: JSON.stringify( + require("../package.json").version + ), + }), // Generate a service worker script that will precache, and keep up to date, // the HTML & assets that are part of the Webpack build. isEnvProduction && diff --git a/src/component/Setting/WebDAV.js b/src/component/Setting/WebDAV.js index 190d558..23fa93a 100644 --- a/src/component/Setting/WebDAV.js +++ b/src/component/Setting/WebDAV.js @@ -292,7 +292,9 @@ export default function WebDAV() { deleteAccount(id) } diff --git a/src/i18n.ts b/src/i18n.ts index 26e3134..e287ba5 100644 --- a/src/i18n.ts +++ b/src/i18n.ts @@ -8,6 +8,8 @@ import ChainedBackend, { ChainedBackendOptions } from "i18next-chained-backend"; import LanguageDetector from "i18next-browser-languagedetector"; import LocalStorageBackend from "i18next-localstorage-backend"; +declare let ASSETS_VERSION: string; + // eslint-disable-next-line @typescript-eslint/ban-ts-ignore // @ts-ignore i18n.use(ChainedBackend) @@ -32,6 +34,7 @@ i18n.use(ChainedBackend) expirationTime: 7 * 24 * 60 * 60 * 1000, // 7 days }, { + queryStringParams: { v: ASSETS_VERSION }, loadPath: "/locales/{{lng}}/{{ns}}.json", }, ], diff --git a/src/utils/index.js b/src/utils/index.js index c5e21b9..9f2c935 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -1,5 +1,3 @@ -import { getResumeCtx } from "../component/Uploader/core/utils"; - export const sizeToString = (bytes) => { if (bytes === 0 || bytes === "0") return "0 B"; const k = 1024; @@ -157,10 +155,9 @@ export function vhCheck() { } export const removeI18nCache = () => { - for (let i = 0, len = localStorage.length; i < len; i++) { - const key = localStorage.key(i); + Object.keys(localStorage).forEach(function (key) { if (key && key.startsWith("i18next_res_")) { localStorage.removeItem(key); } - } + }); };