fix: courses.opengolfapi.org rebuilds every page on every request (4s TTFB) - #2
Open
Geekur wants to merge 1 commit into
Open
fix: courses.opengolfapi.org rebuilds every page on every request (4s TTFB)#2Geekur wants to merge 1 commit into
Geekur wants to merge 1 commit into
Conversation
…e, every request
open-next.config.ts was defineCloudflareConfig({}) with no incrementalCache,
and wrangler.toml bound no R2 bucket or KV namespace. OpenNext therefore had
no store to write rendered pages into, so every prerendered route was rebuilt
from Supabase on every single request.
Measured on courses.opengolfapi.org, 2026-08-10, six consecutive requests:
TTFB 4.06s / 3.89s / 4.02s / 3.87s / 3.81s / 3.93s
x-nextjs-cache: MISS (every time)
x-nextjs-prerender: 1
cache-control: s-maxage=3600, stale-while-revalidate=31532400
robots.txt on the same host: 0.17s
Consistent, not a cold start. The page was prerendered and declared an hour of
cacheability; there was nowhere to put it.
Bucket opengolfapi-next-cache was created for this. The account already runs
this pattern elsewhere (altar-website-opennext-cache, xtrends-web-cache) — the
courses app is the one that never got wired up.
Verified against the installed @opennextjs/cloudflare 1.19.8, not from memory:
the exports map routes ./* to dist/api/*, so the override path resolves, and
r2-incremental-cache.js reads the binding name NEXT_INC_CACHE_R2_BUCKET.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The symptom
courses.opengolfapi.orgtakes ~4 seconds to return its first byte. The network is not the problem — from a host 22ms away, DNS+connect+TLS totals 0.11s androbots.txton the same origin returns in 0.17s.Six consecutive requests:
Consistent. Not a cold start.
The cause
The response already says it is cacheable and prerendered:
But
open-next.config.tswas:No
incrementalCache, andwrangler.tomlbound no R2 bucket and no KV namespace. OpenNext had nowhere to persist a rendered page, so every prerendered route was regenerated from Supabase on every request. The page was built and then thrown away, forever.The fix
plus the binding:
Bucket
opengolfapi-next-cachehas been created.Verified, not assumed
Against the installed
@opennextjs/cloudflare@1.19.8:exportsmap routes./*→./dist/api/*.js, sooverrides/incremental-cache/r2-incremental-cacheresolves to a file that existsr2-incremental-cache.jsreads exactlyNEXT_INC_CACHE_R2_BUCKET— the binding name is not arbitraryThis is not unique to golf
The same empty
defineCloudflareConfig({})appears inmonorepo/opengolfid-webandmonorepo/web. Both are likely paying the same cost and should be checked.Meanwhile the account already has
altar-website-opennext-cacheandxtrends-web-cache— this pattern is already running correctly elsewhere. Courses is the app that got missed.Expected result
First request per route still pays the render. Every subsequent request inside the hour serves from R2 — milliseconds, not seconds.