From 1fbeea14e65e8701aa91587ff418218e4f76d16d Mon Sep 17 00:00:00 2001 From: yuanzonghao Date: Thu, 4 Jun 2026 10:01:06 +0800 Subject: [PATCH] perf(web): pin /home/* assets to 1y immutable cache MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Next.js serves /public files with `Cache-Control: public, max-age=0, must-revalidate`, so the home covers + first-act JSON were re-fetched on every visit. Verified against 30 days of Vercel metrics: /home/* alone was ~62% of Fast Data Transfer egress (5.42 GB) while the files total only ~31 MB — the same bytes re-downloaded hundreds of times. Add a headers() rule scoping `public, max-age=31536000, immutable` to /home/:path* only; other paths keep their defaults (verified /icon.svg still returns no-cache). Filenames under /home are stable (covers fN/mN.webp, first-act JSON by card name), so immutable is safe; if a first-act JSON is ever re-baked under the same name, bump a query string or purge the cache. Co-Authored-By: Claude Opus 4.7 --- next.config.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/next.config.ts b/next.config.ts index 1150341..36a22a4 100644 --- a/next.config.ts +++ b/next.config.ts @@ -6,6 +6,17 @@ const config: NextConfig = { turbopack: { root: __dirname, }, + // /public defaults to `max-age=0, must-revalidate`; pin the stable /home/* covers + first-act JSON for 1y so browsers/CDN stop re-downloading them. + async headers() { + return [ + { + source: "/home/:path*", + headers: [ + { key: "Cache-Control", value: "public, max-age=31536000, immutable" }, + ], + }, + ]; + }, }; export default config;