openvibers/openvibe.live Commits

/live-notify.js: cached 5 minutes, then stale-while-revalidate (other sites load it at a fixed address on every page view; ~980 full downloads in 3 h at max-age=0) (#197)

OP OpenVibers committed 27 days ago · a3e511c6cf · 2 files, +14 −1

Changes

ddiff --git a/server/index.js b/server/index.js
iindex af5fdfc2..61ef81f6 100644
---- a/server/index.js
++++ b/server/index.js
@@@ -639,7 +639,14 @@ app.use((req, res, next) => {
});
// index: false — "/" must reach sendDocument (the SPA fallback), never the raw index.html with its
// unfilled route markers and unversioned asset URLs (a request without Accept: text/html skips SEO).
--app.use(express.static(assets.PUBLIC_DIR, { index: false, setHeaders: (res, filePath) => { if (filePath.endsWith('.html')) noCacheHeaders(res); } }));
++// /live-notify.js is loaded at this fixed address by other OpenVibe sites on every page view (~980 full downloads in
++// three hours on 2026-10-17 at the default max-age=0): five minutes fresh, then served stale while it revalidates, so
++// a change still reaches every site within minutes.
++const LIVE_NOTIFY_CACHE = 'public, max-age=300, stale-while-revalidate=86400';
++app.use(express.static(assets.PUBLIC_DIR, { index: false, setHeaders: (res, filePath) => {
++ if (filePath.endsWith('.html')) noCacheHeaders(res);
++ else if (path.basename(filePath) === 'live-notify.js') res.setHeader('Cache-Control', LIVE_NOTIFY_CACHE);
++} }));
// Ensure data directories exist (all under the data directory, server/paths.js). VOD/clip/paste/
// thumbnail files live in OpenVibe.Media now; what remains is Live-local state (live thumbs, emotes,
ddiff --git a/test/asset-versioning.test.js b/test/asset-versioning.test.js
iindex adf23697..26df2fc3 100644
---- a/test/asset-versioning.test.js
++++ b/test/asset-versioning.test.js
@@@ -129,6 +129,12 @@ async function check(name, fn) {
assert.match(mount[0], /index:\s*false/);
});
++ await check('/live-notify.js (loaded by every site at a fixed address) is cached briefly, then revalidated in the background', () => {
++ const src = fs.readFileSync(path.join(__dirname, '../server/index.js'), 'utf8');
++ assert.match(src, /const LIVE_NOTIFY_CACHE = 'public, max-age=300, stale-while-revalidate=86400';/);
++ assert.match(src, /path\.basename\(filePath\) === 'live-notify\.js'\) res\.setHeader\('Cache-Control', LIVE_NOTIFY_CACHE\)/);
++ });
++
server.close();
fs.rmSync(base, { recursive: true, force: true });
if (failures) { console.log(`\n${failures} failure(s)`); process.exit(1); }