Perf: cache Nitro client assets and parallelize client page

- Serve /swf and /nitro-assets (~2.8GB) with 7-day Cache-Control plus
  stale-while-revalidate so client opens stop re-fetching hundreds of
  files while asset updates still propagate in the background
- Issue the SSO ticket and the online count query in parallel on the
  client page to shave a round-trip off the critical render path
This commit is contained in:
openhands committed 2026-08-26 15:06:16 +02:00
1 parent e7f70bb429
commit 9d0da5d65a
2 files changed
+34 -8

No files matched your search

+22
View File
@@ -125,6 +125,28 @@ const nextConfig: NextConfig = {
},
],
},
{
// Nitro client payload (~2.8GB across swf/nitro-assets): without
// caching every client open re-downloads hundreds of files.
// Fresh for 7 days, then serve stale + revalidate in background
// so asset updates still propagate without blocking players.
source: "/swf/(.*)",
headers: [
{
key: "Cache-Control",
value: "public, max-age=604800, stale-while-revalidate=2592000",
},
],
},
{
source: "/nitro-assets/(.*)",
headers: [
{
key: "Cache-Control",
value: "public, max-age=604800, stale-while-revalidate=2592000",
},
],
},
{
source: "/images/(.*)",
headers: [{ key: "Cache-Control", value: "public, max-age=86400" }],
+12 -8
View File
@@ -21,15 +21,19 @@ export default async function ClientPage() {
]);
const ip = (await headers()).get("x-real-client-ip") ?? "0.0.0.0";
const ticket = await issueSsoTicket(userId, hotelName, ip);
const onlineCount = await cached("online_count", 10_000, async () => {
const [row] = await db
.select({ total: count() })
.from(User)
.where(eq(User.online, "1"));
return row?.total ?? 0;
}).catch(() => 0);
// Ticket write and online count run in parallel — the client page should
// render as fast as possible since the player is waiting for the game.
const [ticket, onlineCount] = await Promise.all([
issueSsoTicket(userId, hotelName, ip),
cached("online_count", 10_000, async () => {
const [row] = await db
.select({ total: count() })
.from(User)
.where(eq(User.online, "1"));
return row?.total ?? 0;
}).catch(() => 0),
]);
return (
<ClientView