perf(web): pin /home/* assets to 1y immutable cache

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 <noreply@anthropic.com>
This commit is contained in:
yuanzonghao
2026-06-04 10:01:06 +08:00
parent b86a9507e3
commit 1fbeea14e6
+11
View File
@@ -6,6 +6,17 @@ const config: NextConfig = {
turbopack: { turbopack: {
root: __dirname, 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; export default config;