Skip to content

The open alternative to Salesforce, designed for AI.

perf(website): cache prerendered pages in CF Cache API (withRegionalCache) (#20905)

Félix Malfait82c565f7dc46
diff --git a/packages/twenty-website/open-next.config.ts b/packages/twenty-website/open-next.config.ts
index 275da561b2a..34c3cbffa72 100644
--- a/packages/twenty-website/open-next.config.ts
+++ b/packages/twenty-website/open-next.config.ts
@@ -1,8 +1,19 @@
import { defineCloudflareConfig } from '@opennextjs/cloudflare';
import r2IncrementalCache from '@opennextjs/cloudflare/overrides/incremental-cache/r2-incremental-cache';
+import { withRegionalCache } from '@opennextjs/cloudflare/overrides/incremental-cache/regional-cache';
+
+// Worker custom-domain hostnames bypass the zone-level Cache Rule for
+// synthetic responses (OpenNext builds responses from R2 reads rather than
+// `fetch()`-ing an origin). Wrapping the R2 incremental cache with the
+// regional cache means cache-hit reads come from CF's per-region Cache API
+// (~10ms) instead of R2 (~100ms), recovering most of the TTFB the migration
+// lost.
+const incrementalCache = withRegionalCache(r2IncrementalCache, {
+ mode: 'long-lived',
+});
const baseConfig = defineCloudflareConfig({
- incrementalCache: r2IncrementalCache,
+ incrementalCache,
});
// `defineCloudflareConfig` only takes the `CloudflareOverrides` subset of the