perf(onboarding-embed): cache the embed page at the Netlify edge - #1162
Merged
Merged
Conversation
/embed/onboarding-form is rendered on demand by a Netlify function and had no cache headers, so every uncached hit paid a cold start (~4s seen on the UK site's iframe; warm hits take ~0.2s). The HTML holds nothing per-visitor (mode, Turnstile and the referrer source are resolved client-side), so serve it from Netlify's durable cache: 5 min fresh, stale-while-revalidate for a day. Browsers still revalidate. The cache key varies on exactly the query params the page reads (locale, country, city, source, languages, bg) via Netlify-Vary, so unknown params neither serve wrong HTML nor bust the cache. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vver2Rh9E4SC5m6ttCpY7V
✅ Deploy Preview for pauseai ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
…wasn't honoured On the deploy preview netlify-cdn-cache-control left the response stored but never fresh (age 0, fwd=miss on every request). Use s-maxage in cache-control instead, as api/notion-image already does. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vver2Rh9E4SC5m6ttCpY7V
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vver2Rh9E4SC5m6ttCpY7V
No measurable gain from durable on the deploy preview; the plain s-maxage config gave verified cache hits. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vver2Rh9E4SC5m6ttCpY7V
…x-age Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vver2Rh9E4SC5m6ttCpY7V
…apply The site runs as Netlify Edge Functions, where durable has no effect. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vver2Rh9E4SC5m6ttCpY7V
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.

Why
The join embed on the UK site loaded slowly.
/embed/onboarding-formis rendered on demand by a Netlify function and sent no cache headers (cache-status: "Netlify Edge"; fwd=miss), so each uncached hit paid a cold start. Measured: 4.1s on a cold hit, 0.15–0.4s warm. The recent university typeahead (#1159) isn't the cause: it adds a 12 KB JSON file and client-side filtering only.What
A
loadinsrc/routes/embed/onboarding-form/+page.server.tssets:cache-control: public, max-age=0, s-maxage=300, stale-while-revalidate=86400(Netlify's edge caches for 5 min; browsers still revalidate)netlify-vary: query=locale|country|city|source|languages|bgNetlify keys on the full query string by default, so unknown params (
?x=1) would each create a cache entry and re-run the function. Listing the six params the page reads keeps the key to those. They live inCACHE_VARY_PARAMS, with a pointer comment in+page.svelteto keep the two in sync.The rendered HTML has no per-visitor input: onboarding mode, Turnstile and the referrer-derived
sourceare all resolved client-side, and nothing reads cookies orAccept-Language. The form POST action is unaffected. A deploy clears the cache.Findings on the deploy preview
netlify-cdn-cache-control(with or withoutdurable,s-maxageormax-age) gave no hits and never showed aNetlify Durablecache-status line. Cause: the site runs as Netlify Edge Functions (USE_EDGE_FUNCTIONS = trueinsvelte.config.js), wheredurableis unsupported. Plains-maxageincache-controldid give hits (cache-status: hit; ttl=297), so that is what is used.Test plan
cache-controlandnetlify-varypresent on the preview responsecache-status: "Netlify Edge"; hit; ttl=…/embed/onboarding-form?country=United%20Kingdomfrom the UK siteprettierandsvelte-checkpass (0 errors).🤖 Generated with Claude Code
https://claude.ai/code/session_01Vver2Rh9E4SC5m6ttCpY7V