mirror of
https://github.com/LucasKalil-Programador/world-2026-hub.git
synced 2026-07-04 17:41:28 -03:00
fix(data): replace DATA_VERSION cache-buster with minute-rounded timestamp
This commit is contained in:
parent
c90e7ba42b
commit
fd7d644a66
1 changed files with 12 additions and 4 deletions
|
|
@ -15,7 +15,15 @@ import { initStats } from './stats.js';
|
||||||
|
|
||||||
let data = null;
|
let data = null;
|
||||||
|
|
||||||
const DATA_VERSION = '2026-06-18-rev3';
|
// Cache-buster rounded down to the current minute: the URL stays stable within
|
||||||
|
// the same minute (so the browser can reuse the response) but changes every
|
||||||
|
// minute, guaranteeing a fresh fetch without ever serving a stale results.json.
|
||||||
|
function dataCacheBust() {
|
||||||
|
const now = new Date();
|
||||||
|
now.setSeconds(0);
|
||||||
|
now.setMilliseconds(0);
|
||||||
|
return now.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
// Optional data layers for the post-tournament stats screen (players, awards,
|
// Optional data layers for the post-tournament stats screen (players, awards,
|
||||||
// editorial — see .agents/stats-screen-plan.md §0.2). They don't exist yet, so
|
// editorial — see .agents/stats-screen-plan.md §0.2). They don't exist yet, so
|
||||||
|
|
@ -25,7 +33,7 @@ const DATA_VERSION = '2026-06-18-rev3';
|
||||||
// error). Never throws — the stats screen lights these up as the JSON lands.
|
// error). Never throws — the stats screen lights these up as the JSON lands.
|
||||||
async function loadOptional(name, fallback) {
|
async function loadOptional(name, fallback) {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`data/${name}.json?v=${DATA_VERSION}`);
|
const res = await fetch(`data/${name}.json?t=${dataCacheBust()}`);
|
||||||
if (!res.ok) return fallback; // not provided yet → empty, no noise
|
if (!res.ok) return fallback; // not provided yet → empty, no noise
|
||||||
return await res.json();
|
return await res.json();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
@ -40,7 +48,7 @@ export async function loadData() {
|
||||||
// Core files are mandatory: a failure here is fatal (throws → showError()).
|
// Core files are mandatory: a failure here is fatal (throws → showError()).
|
||||||
const corePromise = Promise.all(
|
const corePromise = Promise.all(
|
||||||
files.map(async (name) => {
|
files.map(async (name) => {
|
||||||
const res = await fetch(`data/${name}.json?v=${DATA_VERSION}`);
|
const res = await fetch(`data/${name}.json?t=${dataCacheBust()}`);
|
||||||
if (!res.ok) throw new Error(`data/${name}.json — HTTP ${res.status}`);
|
if (!res.ok) throw new Error(`data/${name}.json — HTTP ${res.status}`);
|
||||||
return res.json();
|
return res.json();
|
||||||
}),
|
}),
|
||||||
|
|
@ -95,7 +103,7 @@ async function pollResults() {
|
||||||
if (tournamentOver()) { stopResultsPolling(); return; }
|
if (tournamentOver()) { stopResultsPolling(); return; }
|
||||||
let results;
|
let results;
|
||||||
try {
|
try {
|
||||||
// ?t bypasses the frozen DATA_VERSION + Hostinger's missing cache headers
|
// ?t + no-store bypasses Hostinger's missing cache headers (same scheme loadData uses)
|
||||||
const res = await fetch(`data/results.json?t=${Date.now()}`, { cache: 'no-store' });
|
const res = await fetch(`data/results.json?t=${Date.now()}`, { cache: 'no-store' });
|
||||||
if (!res.ok) return;
|
if (!res.ok) return;
|
||||||
results = await res.json();
|
results = await res.json();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue