From da8a8838c69570a545615ff75386f69f55f54743 Mon Sep 17 00:00:00 2001 From: Lucas Kalil Date: Sun, 14 Jun 2026 00:06:37 -0300 Subject: [PATCH] feat(cache): add cache-busting version for data files --- .agents/project-memory.md | 4 ++++ assets/js/app.js | 4 +++- how-refresh-data.md | 11 ++++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.agents/project-memory.md b/.agents/project-memory.md index 5e3994b..c3cc8dc 100644 --- a/.agents/project-memory.md +++ b/.agents/project-memory.md @@ -242,6 +242,10 @@ Follow `how-refresh-data.md` (project root). In short: - **Sync incremental:** a action mantém `.ftp-deploy-sync-state.json` no servidor; só reenvia arquivos alterados. Não comitar esse arquivo (vive só no servidor). - **Gotcha:** se a Hostinger não aceitar FTPS explícito, trocar `protocol` para `ftp`. Se o site ficar em subpasta, lembrar do gotcha #7 (paths relativos) — já está OK no projeto. +### Data cache-busting via DATA_VERSION (2026-06-14) +- **`assets/js/app.js` `loadData()` appends `?v=${DATA_VERSION}`** to every `data/*.json` fetch (`DATA_VERSION` constant near the top of the file, currently `'2026-06-13-rev1'`). Fixes production browsers/Hostinger caching stale `results.json` after a daily refresh — `cache: 'reload'` only helps the developer's own browser, not real visitors. +- **Must be bumped on every data refresh** — added as step 4 of the daily routine in `how-refresh-data.md`. Format `YYYY-MM-DD-revN`; increment `revN` for same-day re-edits. + ### How to add a UI label 1. Add the key to both `en` and `pt` dicts in `assets/js/i18n.js`. 2. Use `t("key")` at the render site — never hardcode the string. diff --git a/assets/js/app.js b/assets/js/app.js index 99198b3..64e564a 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -14,12 +14,14 @@ import { initBracket } from './bracket.js'; let data = null; +const DATA_VERSION = '2026-06-13-rev1'; + export async function loadData() { if (data) return data; const files = ['teams', 'groups', 'matches', 'results', 'stadiums', 'bracket-config']; const [teams, groups, matches, results, stadiums, bracketConfig] = await Promise.all( files.map(async (name) => { - const res = await fetch(`data/${name}.json`); + const res = await fetch(`data/${name}.json?v=${DATA_VERSION}`); if (!res.ok) throw new Error(`data/${name}.json — HTTP ${res.status}`); return res.json(); }), diff --git a/how-refresh-data.md b/how-refresh-data.md index c511891..e0bbc1e 100644 --- a/how-refresh-data.md +++ b/how-refresh-data.md @@ -65,6 +65,14 @@ Rules: > ⚠️ First pending item: **match id 4 (USA vs Paraguay)** kicked off 2026-06-13 > 01:00 UTC and is still `scheduled` in the data. +### 4. Bump the cache-busting version + +Any time `data/*.json` changes, update `DATA_VERSION` in `assets/js/app.js` +(top of `loadData()`) to today's date, e.g. `'2026-06-14-rev1'`. This is +appended as `?v=...` to every data fetch — without bumping it, visitors on +Hostinger may keep getting yesterday's cached `results.json`. If you edit +data more than once in the same day, increment the `revN` suffix. + --- ## One-time: `thirdPlaceAssignment` (after ~Jun 27–28) @@ -130,4 +138,5 @@ single-source (Wikipedia 17:00 PDT vs one ESPN summary implying 14:00 PDT). Per project convention, append a short dated line to `.agents/project-memory.md` ("results updated through match id N on YYYY-MM-DD") and tick anything completed -in `.agents/TODO.md` §6. +in `.agents/TODO.md` §6. Confirm `DATA_VERSION` in `assets/js/app.js` was bumped +to today's date (step 4 above) before committing.