Skip to content

perf(sentry): Lazy-load Session Replay after page load - #20538

Draft
coolguyzone wants to merge 1 commit into
masterfrom
coolguyzone/perf/lazy-replay
Draft

coolguyzone wants to merge 1 commit into
masterfrom
coolguyzone/perf/lazy-replay

Conversation

@coolguyzone

Copy link
Copy Markdown
Contributor

DESCRIBE YOUR PR

Session Replay is bundled into the docs site's first-load Sentry chunk, which is about 140 KiB compressed and was the most expensive script on doc pages in Lighthouse (about 770 ms of script time on the Next.js guide, mobile). This PR starts the SDK without Replay and adds it from the Sentry CDN with Sentry.lazyLoadIntegration('replayIntegration') once the page has loaded. It's the next step after #20278 (Kapa.ai on demand) and #20537 (lazy platform icons).

  • Remove replayIntegration from Sentry.init in src/instrumentation-client.ts
  • Add Replay after the window load event, with the same maskAllText: false and blockAllMedia: false options. replaysSessionSampleRate and replaysOnErrorSampleRate stay in Sentry.init and still apply.

Why the CDN rather than import('@sentry/nextjs'): this file already imports @sentry/nextjs directly, so a dynamic import of the same package wouldn't move Replay out of the main chunk.

Needs sign-off from whoever relies on the docs-site replays. It changes what gets recorded:

  • Replays start after page load. The first moments of a visit aren't recorded, including errors thrown before Replay loads.
  • Ad blockers can block it. Events go through /sentry-tunnel, but the CDN script comes from browser.sentry-cdn.com, which ad blockers commonly block. Visitors who block it get no replays, though errors and traces still arrive. If that loss is too big, the other option is to bundle @sentry-internal/replay from our own origin as a separate chunk, which means adding that internal package as a direct dependency.

To check the preview: the main Sentry chunk should no longer contain the Replay code, and a request to browser.sentry-cdn.com/.../replay.min.js should appear after the page loads.

IS YOUR CHANGE URGENT?

Help us prioritize incoming PRs by letting us know when the change needs to go live.
Select exactly one option. For deadlines, replace YYYY-MM-DD with the due date. You can update this information later by editing the PR description.

  • Urgent deadline (GA date, etc.): YYYY-MM-DD
  • Other deadline: YYYY-MM-DD
  • No deadline: Not urgent, can wait up to 1 week+

SLA

  • Teamwork makes the dream work, so please add a reviewer to your PRs.
  • Please give the docs team up to 1 week to review your PR unless you've supplied a deadline.

Thanks in advance for your help!

PRE-MERGE CHECKLIST

Make sure you've checked the following before merging your changes:

  • Checked Vercel preview for correctness, including links
  • PR was reviewed and approved by any necessary SMEs (subject matter experts)
  • PR was reviewed and approved by a member of the Sentry docs team

🤖 Generated with Claude Code

Replay was bundled into the first-load Sentry chunk (~140 KiB compressed),
the most expensive script on doc pages in Lighthouse. Init the SDK without
it and add it from the Sentry CDN with lazyLoadIntegration once the window
load event fires. The replay sample rates in Sentry.init still apply.

A dynamic import('@sentry/nextjs') wouldn't split Replay out, because this
file already imports that package statically.

Tradeoffs: replays miss the first moments of a visit, and the CDN request
isn't routed through /sentry-tunnel, so ad blockers that block it leave the
session without Replay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
develop-docs Ready Ready Preview Nov 5, 2026 12:09am UTC
sentry-docs Ready Ready Preview Nov 5, 2026 12:09am UTC

Request Review

This branch was successfully deployed

2 active deployments
Preview – sentry-docs — 7c2c1512 Deployed Nov 5, 2026 by vercel[bot]
Preview – develop-docs — 7c2c1512 Deployed Nov 5, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: Normal Docs review has no urgent deadline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant