Caching serverseitig komplett verhindern (no-store)

- Alle Antworten mit Cache-Control: no-store,no-cache,must-revalidate,max-age=0
  + Pragma/Expires -> Browser UND Proxys (Cloudflare) speichern nichts mehr
- ETag/Last-Modified fuer statische Assets aus
- Behebt: bei manchen Nutzern laden nach Updates alte JS/CSS-Dateien

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Guido
2026-08-05 11:48:09 +02:00
parent ecdbd2ee0d
commit 53cdfc7346
2 changed files with 21 additions and 7 deletions

View File

@@ -49,13 +49,27 @@ if (feet.length < 2) {
const app = express();
app.use(express.json());
// Caching komplett verhindern (Browser UND Proxys wie Cloudflare). Sonst laden bei
// manchen Nutzern nach einem Update alte JS/CSS-Dateien -> "laedt nicht richtig".
const NO_STORE = 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
function noStore(res) {
res.setHeader('Cache-Control', NO_STORE);
res.setHeader('Pragma', 'no-cache');
res.setHeader('Expires', '0');
}
app.use((req, res, next) => {
noStore(res);
next();
});
// Die HTML-Shells nie direkt ausliefern -> immer ueber die Mode-Gates unten
// (verhindert, dass man den private-Modus per /index.html umgeht).
app.get(['/index.html', '/blocked.html'], (req, res) => res.redirect(302, '/'));
// Statische Assets (CSS/JS/Emoji), aber KEIN automatisches index.html (index:false)
app.use(express.static(PUBLIC_DIR, { index: false, setHeaders: (res) => res.setHeader('Cache-Control', 'no-cache') }));
app.use('/library', express.static(LIBRARY_DIR));
// Statische Assets (CSS/JS/Emoji), aber KEIN automatisches index.html (index:false).
// etag/lastModified aus + no-store -> keine (bedingten) Caches, auch nicht in Proxys.
app.use(express.static(PUBLIC_DIR, { index: false, etag: false, lastModified: false, setHeaders: noStore }));
app.use('/library', express.static(LIBRARY_DIR, { etag: false, lastModified: false, setHeaders: noStore }));
// Verfuegbare Bildchen
app.get('/api/feet', (req, res) => {
@@ -125,7 +139,7 @@ app.post('/api/score', (req, res) => {
// ---- Mode-Gates (Live: getMode() liest pro Request die Datei) ----
function sendHtml(res, file) {
res.set('Cache-Control', 'no-cache');
noStore(res);
res.sendFile(join(PUBLIC_DIR, file));
}