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).
This commit is contained in:
Jose Selesan
2026-10-14 12:44:09 -03:00
parent 15c77c07cf
commit e5382670a5

View File

@@ -38,8 +38,28 @@ app.route("/api", expensesRouter);
app.route("/api/telegram", telegramRouter); app.route("/api/telegram", telegramRouter);
app.route("/api/wallets", walletsRouter); app.route("/api/wallets", walletsRouter);
app.use("/assets/*", serveStatic({ root: "./web" })); // Los assets incluyen un hash en el nombre, así que se pueden cachear para
app.get("*", serveStatic({ path: "./web/index.html" })); // 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", () => { eventBus.on("quotes-updated", () => {
cache.invalidateByPrefix("quotes:"); cache.invalidateByPrefix("quotes:");