Skip to main content

How can I reduce the bundle size of JavaScript SDKs?

Issue

The Sentry JavaScript SDK adds weight to my application bundle. I want to reduce how much SDK code ships in production.

Applies To

  • All SaaS Customers and Self-Hosted Users

  • JavaScript SDKs

  • SDK Setup

Resolution

Reduce JavaScript SDK bundle size by shipping only the SDK features you use, tree-shaking optional internal code, and removing unused default integrations.

  1. Import only the features you use. Optional features such as Session Replay, Browser Tracing, and Browser Profiling stay out of the bundle when you do not import and enable them. Details are in the tree shaking documentation.

  2. Tree-shake optional internal SDK code. If you use a Sentry bundler plugin, set bundleSizeOptimizations (for example excludeDebugStatements: true). If you configure the bundler yourself, replace flags such as __SENTRY_DEBUG__ with false. Full steps are in the tree shaking documentation.

  3. Remove unused default integrations. Filter them in Sentry.init, or create a Client with only the integrations you need so unused defaults can be tree-shaken. See removing a default integration and the tree-shaking default integrations section in the tree shaking documentation.

  4. Lazy-load pluggable integrations when you need them later, so they do not add to the initial bundle size. See lazy loading integrations.

Did this answer your question?