openvibers/openvibe.host Commits

Home page: give guests the shared short public cache (#315)

OP OpenVibers committed 6 days ago · c2ec2dffd8 · 1 file, +5 −0

The front page answered no Cache-Control at all: every visit revalidated and a
browser could not reuse what it already had, while /catalog pages next to it
already used openvibe-shared/cache-policy. The home is identical for everyone
signed out, so it now gets "public, max-age=60, stale-while-revalidate=3600"
with Vary: Cookie/Authorization; a signed-in viewer keeps private, no-store.

Changes

ddiff --git a/server/app.js b/server/app.js
iindex d2d2c3a..2432f62 100644
---- a/server/app.js
++++ b/server/app.js
@@@ -296,6 +296,11 @@ async function createApp(opts = {}) {
const o = { title: view.title, description: view.description, body: view.body, viewer: req.viewer, config, path: '/', indexable: true, styles: view.styles, scripts: view.scripts, css: view.css, jsonLd: view.jsonLd, agent: true };
const link = twinHeader(o);
if (link) res.set('Link', link);
++ // The front page is the same for everyone who is not signed in, so a guest may reuse it for
++ // a minute and a half-open browser revalidates behind the stale copy. A viewer's page is
++ // personalised (the account bar), so it stays private and uncached.
++ res.vary('Cookie'); res.vary('Authorization');
++ res.set('Cache-Control', cache.htmlHeaders(req.viewer.kind === 'anonymous' ? { maxAge: 60 } : { private: true }));
res.type('html').send(renderPage(o));
} catch (err) { next(err); }
});