diff --git a/apps/website/instrumentation-client.spec.ts b/apps/website/instrumentation-client.spec.ts index ea7e9d40a..022ee899d 100644 --- a/apps/website/instrumentation-client.spec.ts +++ b/apps/website/instrumentation-client.spec.ts @@ -24,9 +24,17 @@ describe('website posthog init options', () => { autocapture: true, capture_performance: { web_vitals: true }, person_profiles: 'always', + disable_surveys: true, }); }); + // Named for the same reason as the capture_pageview case below: the project's + // remote `surveys: false` does not stop posthog-js downloading surveys.js, + // so dropping this flag silently restores a 33.5KB fetch on every page. + it('keeps the surveys bundle from loading at all', () => { + expect(POSTHOG_INIT_OPTIONS.disable_surveys).toBe(true); + }); + // Redundant with the toEqual above, deliberately: this IS the bug this fix // exists for, and a named failure here is far more legible than an object // diff. Do not "simplify" this away. diff --git a/apps/website/instrumentation-client.ts b/apps/website/instrumentation-client.ts index 6cd82988d..bc8ee2f50 100644 --- a/apps/website/instrumentation-client.ts +++ b/apps/website/instrumentation-client.ts @@ -37,6 +37,16 @@ export const POSTHOG_INIT_OPTIONS = { autocapture: true, capture_performance: { web_vitals: true }, person_profiles: 'always', + /* + * The site runs no surveys, and the project's remote config already says + * `surveys: false` — but that does NOT stop the 33.5KB `surveys.js` download. + * posthog-js loads the extension once the remote value has ARRIVED, whatever + * it is (`if (!isUndefined(remoteSurveys) || advanced_enable_surveys)`), then + * does nothing with it. Only this client flag is checked before that load, so + * the project setting alone can never prevent it. Measured on production with + * mobile throttling, the bundle arrived at ~4.9s on every page. + */ + disable_surveys: true, } satisfies Partial; if (shouldCaptureAnalytics({ token, captureLocal, host: browserHost })) {