Skip to content

Feature loader#233

Open
midweste wants to merge 2 commits intostayallive:masterfrom
midweste:feature-loader
Open

Feature loader#233
midweste wants to merge 2 commits intostayallive:masterfrom
midweste:feature-loader

Conversation

@midweste
Copy link
Copy Markdown

Add support for Sentry's Loader Script (WP_SENTRY_BROWSER_LOADER_URL)

Summary

This PR adds support for using Sentry's Loader Script instead of the bundled SDK for the Browser integration, providing lazy loading capabilities and smaller initial page payloads.

Changes

  • Added new WP_SENTRY_BROWSER_LOADER_URL constant to specify a custom loader script URL
  • When set, the plugin enqueues the loader script with wp_enqueue_script and configures it via inline sentryOnLoad callback
  • Automatically adds data-lazy="no" attribute when tracing or session replay is enabled (since these features require immediate SDK loading)
  • Falls back to bundled SDK if loader URL is not set or invalid
  • Updated readme.txt with documentation for the new option

How it works

// In wp-config.php
define( 'WP_SENTRY_BROWSER_LOADER_URL', 'https://js.sentry-cdn.com/YOUR_KEY.min.js' );

The plugin will:

  1. Enqueue the loader script instead of the bundled SDK
  2. Add an inline script with window.sentryOnLoad containing your configuration
  3. Apply crossorigin="anonymous" and conditional data-lazy attributes

Benefits

  • Smaller initial payload: ~1KB loader vs ~30KB+ bundled SDK
  • Lazy loading: SDK only loads when an error occurs (if tracing/replay disabled)
  • Self-hosted support: Works with both Sentry.io and self-hosted instances
  • Zero breaking changes: Existing configurations continue to work unchanged

Testing

  • Verified loader script is correctly enqueued with proper attributes
  • Confirmed sentryOnLoad callback initializes Sentry with correct options
  • Tested with both Sentry.io and self-hosted Sentry loader URLs
  • Verified data-lazy="no" is applied when tracing or replay is enabled

@szepeviktor
Copy link
Copy Markdown
Contributor

@stayallive Can you lend a click here?

@stayallive
Copy link
Copy Markdown
Owner

It's on my list but I still have to look over this a bit. Thanks for your patience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants