Skip to main content
The Sentry JavaScript SDK is designed to be lightweight, but you can further optimize bundle size by customizing integrations and using tree-shaking.

Bundle Size Impact

Typical bundle sizes (gzipped):
  • Browser SDK (minimal): ~25 KB
  • Browser SDK (with integrations): ~35-45 KB
  • Node SDK: Not relevant for frontend bundles
  • Framework SDKs: Similar to Browser SDK + framework-specific code
The SDK’s bundle size impact is usually minimal compared to other dependencies like React, Vue, or large utility libraries.

Tree-Shaking

Modern bundlers automatically remove unused code:
While namespace imports (import * as Sentry) are convenient and recommended for better DX, named imports (import { init }) may result in slightly smaller bundles with some bundlers.

Selective Integration Loading

Minimal SDK

Disable default integrations and add only what you need:

Conditional Integration Loading

Load heavy integrations only when needed:

Lazy Loading Sentry

Load Sentry asynchronously to improve initial page load:
Lazy loading means errors during initial page load won’t be captured. Only use this if initial load performance is critical.

Smart Lazy Loading

Load immediately on errors, lazily otherwise:

CDN Loading

Use the Sentry CDN bundle to avoid bundling:

Available CDN Bundles

Framework-Specific Optimizations

React

Only import what you need:

Next.js

Next.js SDK is optimized automatically:
Further optimization:

Vue

Bundler Configuration

Webpack

Optimize tree-shaking:

Vite

Vite optimizes automatically, but you can verify:

Rollup

Feature Flags for Bundle Size

Disable Debug Code in Production

The SDK includes debug code that’s stripped in production:

Environment-Based Loading

Measuring Bundle Size

webpack-bundle-analyzer

Vite Plugin Visualizer

Bundle Size Limit

Set size limits to prevent regressions:

Integration Size Reference

Approximate sizes (gzipped):

Best Practices

Review which integrations you’re using and remove unused ones:
Load heavy integrations dynamically:
During development, use CDN bundles to avoid build config:
Switch to npm package for production for better bundling control.
Add bundle size checks to prevent regressions:
The SDK’s impact is usually minimal. Removing error reporting to save 25 KB is rarely worth it.

Complete Minimal Example

Production-Optimized Example

Next Steps

Source Maps

Configure source maps for production

Performance Monitoring

Optimize performance monitoring