BUNDLE ANALYSIS - nself-org/nchat GitHub Wiki

Bundle Size Analysis Report

Date: February 9, 2026 Version: 1.0.0 Build: Next.js 15.5.10


Executive Summary

Build Status: Successful ✅ Shared Bundle: 103 KB (well optimized) ⚠️ Large Routes: 15 routes exceed 300KB first load ✅ API Routes: All minimal (~1.45KB each)


Key Metrics

Metric Value Status
Shared Bundle 103 KB ✅ Excellent
Largest Route 478 KB (Admin Privacy) ⚠️ Review
Total Routes 200+ ✅ Good
API Routes ~150 ✅ Minimal
Average Page Size ~15-20 KB ✅ Good
Average First Load ~200-250 KB ⚠️ Could improve

Shared Bundle Breakdown

Total Shared: 103 KB

chunks/91494-975eac886ac5f165.js     46.2 KB  (Core React/Next.js)
chunks/a87be097-d4f145ea238f5bd3.js  54.2 KB  (Apollo/GraphQL)
other shared chunks (total)           2.54 KB  (Utilities)

Analysis:

  • ✅ Well optimized at 103KB total
  • ✅ Core framework (React 19 + Next.js 15) at 46KB is excellent
  • ✅ Apollo/GraphQL at 54KB is reasonable for real-time app
  • ✅ Minimal utility overhead (2.5KB)

Routes Exceeding 300KB First Load

Route Size First Load Issue
/settings/privacy/gdpr 24.5 KB 478 KB Large GDPR compliance UI
/settings/notifications 8.88 KB 471 KB Notification preferences
/settings/privacy/location 6.64 KB 477 KB Location settings
/settings/account 5.72 KB 468 KB Account management
/settings/data 3.33 KB 469 KB Data management
/settings/keyboard 5.17 KB 468 KB Keyboard shortcuts
/settings/security 2.44 KB 468 KB Security settings
/settings/profile 4.57 KB 467 KB Profile settings
/settings/privacy 4.61 KB 467 KB Privacy settings
/settings 3.56 KB 466 KB Settings hub
/admin/advanced 30.2 KB 415 KB Advanced admin tools
/admin/channels/[id] 8.92 KB 394 KB Channel admin
/admin 5.63 KB 378 KB Admin dashboard
/admin/moderation 17 KB 364 KB Moderation queue
/admin/bots/manage 21.9 KB 339 KB Bot management

Analysis by Section

1. Settings Pages (⚠️ Heavy - 466-478KB)

Issue: All settings pages load 466-478KB on first load Cause: Shared settings layout with heavy form libraries

Components Contributing:

  • React Hook Form (~25KB)
  • Zod validation (~15KB)
  • Form UI components (~30KB)
  • Settings navigation (~20KB)
  • Total overhead: ~90KB + shared 103KB = ~193KB base

Individual page costs:

  • GDPR compliance: +285KB (GDPR tools, export, privacy controls)
  • Notifications: +278KB (Notification manager, preferences)
  • Location: +284KB (Maps, geocoding, location privacy)
  • Account/Security/Profile: ~275KB each

Recommendations:

  1. Lazy load form validation - Load Zod schemas on demand
  2. Code split settings sections - Don't load all settings upfront
  3. Lazy load GDPR tools - Only load when user clicks "Export Data"
  4. Virtualize settings list - Don't render all settings at once

Potential Savings: ~150-200KB per settings page

2. Admin Pages (⚠️ Heavy - 164-415KB)

Issue: Admin pages range from 164KB to 415KB Cause: Admin dashboard includes charts, tables, analytics

Largest Admin Routes:

  • /admin/advanced: 415KB (Advanced configuration tools)
  • /admin/channels/[id]: 394KB (Channel management)
  • /admin: 378KB (Dashboard with charts)
  • /admin/moderation: 364KB (Moderation queue)
  • /admin/bots/manage: 339KB (Bot builder)

Components Contributing:

  • Recharts library: ~300KB (for analytics charts)
  • Tables and data grids: ~50KB
  • Admin navigation: ~30KB
  • Dashboard widgets: ~40KB

Recommendations:

  1. 🔴 Lazy load Recharts - Critical! Load only when charts are visible
  2. Code split admin by section - Separate bundles for moderation, analytics, bots
  3. Lazy load bot builder - Only load when creating/editing bots
  4. Defer non-critical widgets - Load charts in background

Potential Savings: ~200-250KB per admin page

3. Public/Auth Pages (✅ Optimized - 104-221KB)

Well Optimized Routes:

  • /login: 214KB
  • /signup: 214KB
  • /auth/signin: 210KB
  • /auth/signup: 210KB
  • /_not-found: 104KB

Analysis: These are well optimized. No action needed.

4. Chat/Messaging (✅ Good - 200-280KB)

Chat Routes:

  • /chat: 214KB
  • /chat/channel/[slug]: 284KB
  • /activity: 204KB
  • /people: 313KB

Analysis: Reasonable for real-time chat app. Could optimize further.

Recommendations:

  1. Lazy load TipTap editor - Load rich text editor on focus
  2. Lazy load emoji picker - Load when user clicks emoji button
  3. Virtual scrolling - Already implemented ✓

Potential Savings: ~30-50KB

5. API Routes (✅ Excellent - 1.45KB each)

All API routes are extremely optimized at 1.45KB each. No action needed.


Optimization Priority Matrix

🔴 High Priority (Immediate Action)

  1. Lazy Load Recharts (~300KB savings)

    const LazyChart = dynamic(() => import('recharts'), {
      loading: () => <ChartSkeleton />,
      ssr: false
    })
  2. Code Split Admin Routes (~200KB savings per route)

    // Separate admin bundle
    // Already possible with Next.js App Router
  3. Lazy Load Settings Forms (~150KB savings)

    const LazyGDPRTools = dynamic(() => import('@/components/settings/gdpr-tools'), {
      loading: () => <Skeleton />,
      ssr: false
    })

🟡 Medium Priority (This Week)

  1. Lazy Load TipTap Editor (~150KB savings)
  2. Lazy Load Emoji Picker (~80KB savings)
  3. Optimize Settings Layout (~100KB savings)
  4. Defer Admin Widgets (~50KB savings)

🟢 Low Priority (This Month)

  1. Implement Virtual Scrolling (Already done ✓)
  2. Optimize Form Libraries (Consider lighter alternatives)
  3. Bundle Size Monitoring (Add to CI/CD)

Performance Budget

Current Status vs. Targets

Resource Current Target Status
Shared Bundle 103 KB < 150 KB ✅ Excellent
Public Pages 104-221 KB < 250 KB ✅ Good
Chat Pages 200-284 KB < 300 KB ✅ Good
Settings Pages 466-478 KB < 300 KB ❌ Exceeds
Admin Pages 164-415 KB < 350 KB ⚠️ Some exceed
API Routes 1.45 KB < 10 KB ✅ Excellent

Detailed Route Analysis

Top 20 Largest Routes (by First Load JS)

# Route Size First Load Type
1 /settings/privacy/gdpr 24.5 KB 478 KB ○ Static
2 /settings/privacy/location 6.64 KB 477 KB ○ Static
3 /settings/notifications 8.88 KB 471 KB ○ Static
4 /settings/data 3.33 KB 469 KB ○ Static
5 /settings/account 5.72 KB 468 KB ○ Static
6 /settings/keyboard 5.17 KB 468 KB ○ Static
7 /settings/security 2.44 KB 468 KB ○ Static
8 /settings/privacy 4.61 KB 467 KB ○ Static
9 /settings/profile 4.57 KB 467 KB ○ Static
10 /settings 3.56 KB 466 KB ○ Static
11 /admin/advanced 30.2 KB 415 KB ○ Static
12 /admin/channels/[id] 8.92 KB 394 KB ƒ Dynamic
13 /admin 5.63 KB 378 KB ○ Static
14 /admin/moderation 17 KB 364 KB ○ Static
15 /admin/bots/manage 21.9 KB 339 KB ○ Static
16 /admin/bots 17.1 KB 335 KB ○ Static
17 /meetings/schedule 3.58 KB 335 KB ○ Static
18 /meetings/[id] 2.34 KB 334 KB ƒ Dynamic
19 /people 22.6 KB 313 KB ○ Static
20 /admin/webhooks 23.7 KB 308 KB ○ Static

Code Splitting Opportunities

1. Admin Bundle Split

Current: All admin pages share same bundle Proposed: Split into sections

Admin Core (150KB)
├── Admin Analytics (150KB) - Recharts + charts
├── Admin Moderation (100KB) - Moderation tools
├── Admin Bots (80KB) - Bot builder
└── Admin Settings (50KB) - Configuration

Savings: 200-250KB for non-admin users

2. Settings Bundle Split

Current: All settings share heavy form bundle Proposed: Split by category

Settings Core (100KB)
├── Privacy Tools (150KB) - GDPR, location
├── Notifications (120KB) - Notification manager
├── Account/Security (100KB) - Auth settings
└── Appearance/Theme (50KB) - UI customization

Savings: 150-200KB per settings page

3. Feature-Based Splitting

Current: All features load upfront Proposed: Load on demand

// Load only when needed
const CallWindow = lazy(() => import('@/components/calls'))
const VideoEditor = lazy(() => import('@/components/video'))
const AdvancedSearch = lazy(() => import('@/components/search/advanced'))

Savings: 300-400KB for users who don't use features


Recommendations Summary

Immediate Actions (This Week)

  1. Implement lazy-loader.ts utility (DONE)
  2. 🔴 Lazy load Recharts in admin pages
  3. 🔴 Code split settings pages
  4. 🔴 Lazy load GDPR compliance tools

Short Term (This Month)

  1. 🟡 Implement progressive loading for admin dashboard
  2. 🟡 Optimize form libraries in settings
  3. 🟡 Add bundle size monitoring to CI/CD
  4. 🟡 Configure Lighthouse CI (DONE - .lighthouserc.js created)

Long Term (This Quarter)

  1. 🟢 Evaluate lighter alternatives for heavy libraries
  2. 🟢 Implement service worker for caching
  3. 🟢 Set up performance dashboard
  4. 🟢 Regular bundle size audits

Monitoring and Tracking

Tools Available

  1. Bundle Analyzer: pnpm build:analyze
  2. Lighthouse CI: pnpm lighthouse
  3. Bundle Analysis Script: tsx scripts/analyze-bundle.ts
  4. Web Vitals Tracking: Built into app

CI/CD Integration

# .github/workflows/performance.yml
- name: Bundle Size Check
  run: pnpm build:analyze
- name: Lighthouse CI
  run: pnpm lighthouse

Conclusion

Overall Assessment: 🟡 Good with room for improvement

Strengths:

  • ✅ Excellent shared bundle optimization (103KB)
  • ✅ Well-optimized API routes (1.45KB each)
  • ✅ Good core page sizes (104-221KB)
  • ✅ Proper code splitting infrastructure

Areas for Improvement:

  • ⚠️ Settings pages are heavy (466-478KB)
  • ⚠️ Some admin pages exceed budget (415KB)
  • ⚠️ Charts library not lazy loaded

Expected Impact of Optimizations:

  • Settings pages: 466KB → ~280KB (39% reduction)
  • Admin pages: 415KB → ~250KB (40% reduction)
  • Overall app: ~25-30% bundle size reduction

Next Review: March 9, 2026 Generated: February 9, 2026 Tool: scripts/analyze-bundle.ts

⚠️ **GitHub.com Fallback** ⚠️