I operate GamerScroll, a free web archive that tracks daily App Store and Google Play Top 200 mobile game rankings across five markets (US, Japan, South Korea, Taiwan, and China iOS) in five languages.
When the site grew to thousands of individual game detail pages multiplied across five language editions, pre-building every single HTML file in CI became too slow and hit static deployment limits. Moving game detail pages to Cloudflare Pages Functions solved the build problem, then immediately ran into the Cloudflare Workers Free tier limit: 10 ms of CPU time per request.
Here are the four engineering changes that kept request-time rendering fast and reliable without adding a database server.
1. Pay V8 Compilation Once at Isolate Startup, Not Per Request
On the first request to a fresh isolate, loading the template module graph for a language edition and rendering the first page took roughly 55 ms of CPU time. Under a 10 ms per-request cap, cold requests failed with CPU limit errors before edge caching could help.
Cloudflare Workers gives module initialization (global scope) a separate 1-second startup budget. Instead of lazily initializing each edition renderer inside the request handler, the worker warms up all five edition renderers once at module load using a tiny dummy payload:
const renderers = new Map(); function rendererFor(code) { if (!renderers.has(code)) renderers.set(code, createRenderer(code)); return renderers.get(code); } try { for (const code of Object.keys(PREFIX)) { rendererFor(code).render(WARMUP.game, WARMUP.meta); } } catch { // Keep the isolate alive so middleware and other routes continue working } Once V8 finishes compiling the renderers during isolate startup, steady-state request renders drop well under the 10 ms ceiling.
2. The esbuild keepNames Trap With Inline Scripts
One subtle bug appeared only after deploying to Cloudflare Pages Functions. Cloudflare bundles functions/ using esbuild with keepNames enabled, which wraps named functions in a helper call like __name(fn, "fn").
Because some lightweight chart interactions were serialized directly into <script> tags from template helpers via Function.prototype.toString(), those __name(...) wrappers leaked into the browser HTML and threw ReferenceError: __name is not defined.
The fix was a one-line pass-through shim injected right after <head> before any inline script runs:
const NAME_SHIM = '<script>var __name=function(f){return f};</script>'; function withNameShim(html) { const at = html.indexOf('<head>'); return at < 0 ? NAME_SHIM + html : html.slice(0, at + 6) + NAME_SHIM + html.slice(at + 6); } It avoided rewriting every interactive chart helper while keeping the SSR bundle identical to the local Node test runner.
3. Split Heavy Sections Between SSR Text and Lazy Client Hydration
Individual game pages include multi-market rank histories and beta estimate charts. Rendering every SVG plot and table for every market-store tab on the server would blow the 10 ms CPU budget on popular titles.
Instead, the same template module runs in two modes:
- Server pass (Workers): parses only the portion of the static JSON file needed for headings, summaries, and SEO metadata, and emits fixed-height placeholder boxes for charts and non-default tabs.
- Browser pass: a tiny
IntersectionObserverscript loads the client bundle only when the section comes within1200pxof the viewport, then fills each placeholder using the exact same rendering path.
This keeps initial HTML fast and crawlable while avoiding unnecessary client JavaScript on pages where the user never scrolls that far.
4. Content-Addressed Edge Cache Keys Across Deploys
All game payloads live as static JSON files (docs/games-data/<slug>.json) alongside a shared _meta.json. Rather than caching HTML purely by URL (which forces awkward purge logic on every deploy), the Pages Function hashes the game JSON bytes and combines them with the metadata and bundle versions:
async function pageVersion(bytes, meta) { const digest = new Uint8Array(await crypto.subtle.digest('SHA-1', bytes)); const hex = Array.from(digest.subarray(0, 8), (b) => b.toString(16).padStart(2, '0')).join(''); return `${hex}.${meta.version}.${BUNDLE_VERSION}`; } A game whose data did not change between deploys keeps its warm Cloudflare edge cache entry automatically, while any updated title invalidates immediately on its next request.
Daily Data Collection Without a Backend Database
For data ingestion, a scheduled GitHub Actions workflow runs a Node.js collector across five countries in parallel (us, jp, kr, tw, cn), keeping requests sequential within each country to avoid throttling store endpoints. On iOS, it queries the viewTop endpoint first and falls back to RSS if needed; on Android, it pulls Top Grossing and Top Free Top 200 lists for the four Google Play markets.
The output is written into daily history JSON snapshots, compiled into edition-specific static ranking hubs (US, Japan, South Korea, Taiwan, China) and a client-side daily ranking archive, and deployed directly to Cloudflare Pages.
If you are building a data-heavy multi-language site on static hosting, moving heavy compilation to isolate startup and keeping data in content-addressed JSON assets goes a long way before you ever need a paid database or server tier.
