« get me outta code hell

infra: use nicer cachebust string instead of Date.now() - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-03-29 09:41:50 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-03-29 09:41:50 -0300
commit179520dca821a149f1a8cd73204e0fead02ed555 (patch)
tree11b658b5fb592c7515d3c86159d5f255c073337c
parent47a2d6a9adf5059c194350e61d6beb3ff083088c (diff)
infra: use nicer cachebust string instead of Date.now()
-rw-r--r--src/content/dependencies/index.js14
1 files changed, 13 insertions, 1 deletions
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}`;