Skip to content

feat(frontend): optimize bundle size with dynamic imports and route-based code splitting - #88

Merged
jobbykings merged 1 commit into
Epondia:mainfrom
Agbasimere:feature/bundle-optimization
Jun 22, 2026
Merged

feat(frontend): optimize bundle size with dynamic imports and route-based code splitting#88
jobbykings merged 1 commit into
Epondia:mainfrom
Agbasimere:feature/bundle-optimization

Conversation

@Agbasimere

Copy link
Copy Markdown
Contributor

Description

This PR implements dynamic imports, route-based code splitting, and lazy loading for non-critical features (AR/VR, Metaverse, Lab, and BCI) to optimize the initial page load bundle sizes.

Key Changes

  1. Removed Custom splitChunks Overrides: The previous config forced all of node_modules into a single shared vendors.js chunk, bloating every route to 1.61 MB. Reverting to Next.js's defaults restored optimal code splitting.
  2. Web-Vitals & Performance Monitor Isolation: Created PerformanceInitializer.tsx to lazy load performance-monitor on client-side mount, keeping it out of the server rendering path.
  3. Dynamic Module Entry Points: Exported all heavy modules (AR/VR, Metaverse, Lab, BCI) using next/dynamic with ssr: false in their folder index files:
    • ARVR index.ts
    • Metaverse index.ts
    • Lab index.ts
    • BCI index.ts
  4. Official @next/bundle-analyzer Wrapper: Added it to package.json and configured next.config.js to avoid duplicate bundle reports.

Verification Results

  • First Load JS shared by all app router pages: Reduced from 1.61 MB to 88.2 kB.
  • Landing Page Initial Bundle Size: ~100 KB gzipped (512 kB raw, including the root Web3 provider).
  • Three.js, D3, and TensorFlow: Successfully code-split and only loaded when navigating to /campus, /lab, and /bci-dashboard respectively.
  • Unit Tests: ErrorBoundary and RouteErrorBoundary test suites ran and passed successfully (59/59 passed).

Closes #73

@jobbykings
jobbykings merged commit 071a1f6 into Epondia:main Jun 22, 2026
5 checks passed
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.

Optimize frontend bundle size with code splitting and tree shaking

2 participants