Skip to content

Commit cfb2065

Browse files
boojackclaude
andcommitted
perf(web): edge-cache public pages; drop static-split build
Take the standard single-Worker path instead of the static-split: add Cache-Control (s-maxage + stale-while-revalidate) to the public marketing/docs routes so Cloudflare's CDN serves repeat hits to the same URL without invoking the Worker. Scoped to public paths only — /api, /dashboard, /sign-in, /sign-up, /scratchpad stay dynamic/no-store. Removes the interim static-split artifacts (scripts/build-web-static.mjs, wrangler.web.jsonc, build:web/deploy:web) — the split fought OpenNext's single-deployment model and the apex re-routing was too risky for the benefit. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 58762b1 commit cfb2065

5 files changed

Lines changed: 30 additions & 121 deletions

File tree

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,3 @@ openapi.yaml
4141

4242
# clerk configuration (can include secrets)
4343
/.clerk/
44-
45-
# static-split: web export build (out/ already ignored above) + build stash
46-
/.web-static-stash

next.config.mjs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,32 @@ const SECURITY_HEADERS = [
3434
},
3535
];
3636

37+
// Edge-cache the static public pages so Cloudflare's CDN can serve repeat hits
38+
// to the same URL without invoking the Worker (zero CPU/request). Content is
39+
// immutable until redeploy (pages are `revalidate = false`); s-maxage keeps it
40+
// fresh for an hour and stale-while-revalidate serves instantly while the edge
41+
// refreshes in the background. Scoped to public routes only — never /api,
42+
// /dashboard, /sign-in, /sign-up, or /scratchpad (those stay no-store/dynamic).
43+
const PUBLIC_CACHE_HEADERS = [
44+
{
45+
key: "Cache-Control",
46+
value: "public, s-maxage=3600, stale-while-revalidate=86400",
47+
},
48+
];
49+
const PUBLIC_CACHEABLE_PATHS = [
50+
"/",
51+
"/docs/:path*",
52+
"/blog/:path*",
53+
"/changelog/:path*",
54+
"/features/:path*",
55+
"/use-cases/:path*",
56+
"/compare/:path*",
57+
"/pricing",
58+
"/brand",
59+
"/privacy",
60+
"/sponsors",
61+
];
62+
3763
/** @type {import('next').NextConfig} */
3864
const config = {
3965
poweredByHeader: false,
@@ -85,6 +111,10 @@ const config = {
85111
source: "/:path*",
86112
headers: SECURITY_HEADERS,
87113
},
114+
...PUBLIC_CACHEABLE_PATHS.map((source) => ({
115+
source,
116+
headers: PUBLIC_CACHE_HEADERS,
117+
})),
88118
];
89119
},
90120
};

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
"preview": "opennextjs-cloudflare build && opennextjs-cloudflare preview",
1515
"deploy": "node scripts/verify-deploy-env.mjs && opennextjs-cloudflare build && opennextjs-cloudflare deploy -- --keep-vars",
1616
"deploy:dry-run": "opennextjs-cloudflare build && wrangler deploy --dry-run",
17-
"build:web": "node scripts/build-web-static.mjs",
18-
"deploy:web": "node scripts/build-web-static.mjs && wrangler deploy --config wrangler.web.jsonc",
1917
"typegen": "wrangler types --env-interface CloudflareEnv cloudflare-env.d.ts",
2018
"smoke": "node scripts/smoke-test.mjs",
2119
"og:audit": "node scripts/og-audit.mjs",

scripts/build-web-static.mjs

Lines changed: 0 additions & 87 deletions
This file was deleted.

wrangler.web.jsonc

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)