From e5382670a5e6707eef33e3ac3c121ee1671fa144 Mon Sep 17 00:00:00 2001 From: Jose Selesan Date: Wed, 14 Oct 2026 12:44:09 -0300 Subject: [PATCH] fix(web): cache hashed assets immutably and never cache the SPA shell Hash-named assets under /assets can be cached for a year with immutable, but index.html must not be cached. Otherwise a previously cached shell keeps loading the old bundle after a deploy, masking frontend fixes (e.g. the monthly variation table still rendering the old extra blank row). --- apps/backend/src/index.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/apps/backend/src/index.ts b/apps/backend/src/index.ts index 0e750f3..423abea 100644 --- a/apps/backend/src/index.ts +++ b/apps/backend/src/index.ts @@ -38,8 +38,28 @@ app.route("/api", expensesRouter); app.route("/api/telegram", telegramRouter); app.route("/api/wallets", walletsRouter); -app.use("/assets/*", serveStatic({ root: "./web" })); -app.get("*", serveStatic({ path: "./web/index.html" })); +// Los assets incluyen un hash en el nombre, así que se pueden cachear para +// siempre. El index.html no debe cachearse: referencia los assets con hash y, +// si queda cacheado, el navegador sigue sirviendo el bundle viejo después de +// un deploy (por eso una nueva versión no se ve hasta un hard refresh). +app.use( + "/assets/*", + serveStatic({ + root: "./web", + onFound: (_path, c) => { + c.header("Cache-Control", "public, max-age=31536000, immutable"); + }, + }), +); +app.get( + "*", + serveStatic({ + path: "./web/index.html", + onFound: (_path, c) => { + c.header("Cache-Control", "no-cache"); + }, + }), +); eventBus.on("quotes-updated", () => { cache.invalidateByPrefix("quotes:");