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

@@ -6,9 +6,9 @@ const $ = (id) => document.getElementById(id);
// ---- Konstanten (leicht justierbar) ---- // ---- Konstanten (leicht justierbar) ----
const START_TIME = 22; // Sekunden zu Beginn const START_TIME = 22; // Sekunden zu Beginn
const MAX_TIME = 30; // Deckel (Timerleiste = timeLeft / MAX_TIME) const MAX_TIME = 20; // Deckel (Timerleiste = timeLeft / MAX_TIME)
const BONUS = 2.0; // Zeit pro Treffer const BONUS = 1.0; // Zeit pro Treffer
const PENALTY = 2.0; // Zeitabzug pro Fehlklick const PENALTY = 3.0; // Zeitabzug pro Fehlklick
const NAME_KEY = 'fuesse_name'; const NAME_KEY = 'fuesse_name';
// ---- Zustand ---- // ---- Zustand ----

View File

@@ -49,13 +49,27 @@ if (feet.length < 2) {
const app = express(); const app = express();
app.use(express.json()); 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 // Die HTML-Shells nie direkt ausliefern -> immer ueber die Mode-Gates unten
// (verhindert, dass man den private-Modus per /index.html umgeht). // (verhindert, dass man den private-Modus per /index.html umgeht).
app.get(['/index.html', '/blocked.html'], (req, res) => res.redirect(302, '/')); app.get(['/index.html', '/blocked.html'], (req, res) => res.redirect(302, '/'));
// Statische Assets (CSS/JS/Emoji), aber KEIN automatisches index.html (index:false) // 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') })); // etag/lastModified aus + no-store -> keine (bedingten) Caches, auch nicht in Proxys.
app.use('/library', express.static(LIBRARY_DIR)); 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 // Verfuegbare Bildchen
app.get('/api/feet', (req, res) => { 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) ---- // ---- Mode-Gates (Live: getMode() liest pro Request die Datei) ----
function sendHtml(res, file) { function sendHtml(res, file) {
res.set('Cache-Control', 'no-cache'); noStore(res);
res.sendFile(join(PUBLIC_DIR, file)); res.sendFile(join(PUBLIC_DIR, file));
} }