The Homepage That Never Hit the CDN
How we traced okayok.ai’s slow first paint to uncacheable HTML, a sin1→iad1 SSR hop, Set-Cookie cache busting, and a later geo×CDN conflict — and what Shipokay-style multi-site scaffolds copy by default.
When someone opens okayok.ai, they are not asking for a dashboard. They want the brand page to appear. If the first paint feels sticky, the whole product family feels slow — even when images, fonts, and marketing copy are fine.
This is the engineering story of that stickiness: what we measured, what we fixed, and the trap we walked into next.
What it looked like
From a user’s seat, the homepage “just took a while.” From the network tab, the story was sharper.
During diagnosis (not a formal before/after launch study), we saw roughly:
- Cold HTML TTFB around several seconds (one cold sample near ~4.9s); a follow-up request still around ~2.6s
X-Vercel-Cache: MISSon the document, every timeCache-Control: max-age=0on HTML — the browser was told to revalidate, and the edge never kept a useful copy either- First Contentful Paint in the browser around ~2.7s in that session
JS and fonts were heavy (main bundle on the order of hundreds of KB), but they were secondary. The document itself was the bottleneck.
The real causes
Three structural issues stacked.
1. Marketing HTML never lived at the edge
A homepage that SSR’s on every visit is fine if the work is cheap and local. Ours was neither. The response was effectively uncacheable, so every first visit paid origin SSR again. “MISS forever” is not a CDN failure — it is a product of response headers and side effects.
2. Cross-region work inside SSR
The site’s Vercel region was sin1 (Singapore). Critical API data lived behind iad1 (US East). The root loader pulled product-family and analytics configuration on the document path. So a visitor in Asia waited for Singapore to call the US before HTML could finish.
That hop is easy to miss in local vite dev. It only shows up when production geography is real.
3. Set-Cookie on the document response
Attribution (utm_*) and geo/session cookies were convenient to set on the HTML response. Convenient, and fatal for shared caches: once the document is personalized with Set-Cookie, intermediaries treat it as private. You can write the perfect s-maxage and still never HIT.
What we changed
The fix direction was boring on purpose:
- Build-time family snapshot — bake the product/footer graph into the repo at build time so SSR does not cross the Pacific for marketing chrome.
- Short public HTML edge cache — marketing pages get something like
public, max-age=0, s-maxage=300, stale-while-revalidate=86400(and matching CDN cache headers), while auth/app/admin stayprivate, no-store. - Move utm / geo off the document — write those cookies from the client (or dedicated endpoints) so the HTML response can stay shareable.
We rolled the same pattern across the Okayok family sites — including templates in the Shipokay / ShipAny TanStack scaffold — because copying a working marketing stack also copies its cache bugs.
We are deliberately not quoting unverified “after launch” latency wins here. Diagnosis numbers above are from the investigation window; production HIT rates need to be checked with headers after deploy (Age, X-Vercel-Cache, absence of stray Set-Cookie on /).
The plot twist: geo × CDN
Caching the homepage fixed the slow path and broke a correctness path.
Locale geo-redirect lived in a server wrapper (withGeo) on the origin. Once the edge started serving HIT HTML, that wrapper never ran. A visitor who should have landed on /zh could receive a cached English document instead. Client cookie hydration alone did not equal a locale redirect.
That is the High finding from review, and it is the honest part of this post: edge cache and origin-only redirects do not compose.
The durable pattern is to keep a single pure locale decision (URL path + country + Accept-Language), run it on the server when the request reaches origin, and run the same decision in the browser when the document came from cache. Marketing HTML can stay public; geo does not get to veto the CDN by smuggling cookies onto every response.
Takeaways
- First paint problems often are document problems, not image problems.
MISSwithmax-age=0is a clue;Set-Cookieon HTML is a confession.- Cross-region SSR is invisible until you deploy regions for real.
- Multi-site scaffolds (Shipokay included) multiply both fixes and bugs — treat cache policy as shared infrastructure, not a one-off site tweak.
- When you finally get CDN HIT, re-test every origin middleware assumption (geo, auth gates, A/B). HIT means those assumptions are gone.
Slow homepages are rarely one villain. Ours was uncacheable HTML, a long SSR dependency, cookie side effects, and then a geo redirect that only worked when we were still slow. Making the page fast forced us to make the redirect correct under cache — which is the version of “done” that actually ships.