From 179520dca821a149f1a8cd73204e0fead02ed555 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 29 Mar 2023 09:41:50 -0300 Subject: infra: use nicer cachebust string instead of Date.now() --- src/content/dependencies/index.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/content/dependencies/index.js') diff --git a/src/content/dependencies/index.js b/src/content/dependencies/index.js index 767828ad..c2d88f64 100644 --- a/src/content/dependencies/index.js +++ b/src/content/dependencies/index.js @@ -7,6 +7,18 @@ import contentFunction from '../../content-function.js'; import {color, logWarn} from '../../util/cli.js'; import {annotateFunction} from '../../util/sugar.js'; +function cachebust(filePath) { + if (filePath in cachebust.cache) { + cachebust.cache[filePath] += 1; + return `${filePath}?cachebust${cachebust.cache[filePath]}`; + } else { + cachebust.cache[filePath] = 0; + return filePath; + } +} + +cachebust.cache = Object.create(null); + export function watchContentDependencies({ mock = null, logging = true, @@ -119,7 +131,7 @@ export function watchContentDependencies({ main: { let spec; try { - spec = (await import(`${filePath}?${Date.now()}`)).default; + spec = (await import(cachebust(filePath))).default; } catch (caughtError) { error = caughtError; error.message = `Error importing: ${error.message}`; -- cgit 1.3.0-6-gf8a5