Skip to content

feat: implement route-based code splitting with React.lazy and Suspense#240

Open
samalbishnupriya06-stack wants to merge 1 commit into
DeadIndian:mainfrom
samalbishnupriya06-stack:feat/route-based-code-splitting
Open

feat: implement route-based code splitting with React.lazy and Suspense#240
samalbishnupriya06-stack wants to merge 1 commit into
DeadIndian:mainfrom
samalbishnupriya06-stack:feat/route-based-code-splitting

Conversation

@samalbishnupriya06-stack

Copy link
Copy Markdown

🔗 Related Issue

Closes #106


🧩 What Changed

  • Replaced direct imports of Dashboard, Profile, AuthForms, About, and Contact
    with React.lazy() for dynamic imports.
  • Wrapped <Routes> in <Suspense fallback={<LoadingSpinner />}> for a smooth
    loading experience during navigation.
  • Created a new LoadingSpinner component used as the Suspense fallback UI.

📂 Files Modified

File Change
client/src/App.jsx Replaced static imports with lazy(), added <Suspense>
client/src/components/LoadingSpinner.jsx New file — fallback spinner component

✅ How to Verify

  1. Run cd client && npm run dev
  2. Open Chrome DevTools → Network tab → filter by JS
  3. Navigate to /dashboard, /profile, etc.
  4. Confirm new .js chunks (e.g., Dashboard-abc123.js) load on demand,
    not all at once on initial page load.

💡 Why This Matters

  • Faster TTI — Users only download code for the page they visit.
  • Scalable — New pages/features won't bloat the initial bundle.
  • Best Practice — Standard for production React apps with multiple routes.

🧪 Checklist

  • Code runs locally without errors
  • No existing functionality broken
  • Spinner shows briefly during navigation (especially on slow 3G)
  • Follows existing code style

@samalbishnupriya06-stack

Copy link
Copy Markdown
Author

@DeadIndian can you please review this PR ?

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.

Performance Enhancement: Implement Code Splitting and Lazy Loading for Route Components

1 participant