Ask any question about Web Development here... and get an instant response.
Post this Question & Answer:
How can I improve the performance of a React app using lazy loading and code splitting?
Asked on Feb 09, 2026
Answer
Improving the performance of a React app using lazy loading and code splitting involves breaking down your application into smaller chunks that can be loaded on demand, reducing the initial load time. React's `React.lazy` and `Suspense` are commonly used for this purpose.
<!-- BEGIN COPY / PASTE -->
import React, { Suspense, lazy } from 'react';
const LazyComponent = lazy(() => import('./LazyComponent'));
function App() {
return (
<div>
<Suspense fallback={<div>Loading...</div>}>
<LazyComponent />
</Suspense>
</div>
);
}
export default App;
<!-- END COPY / PASTE -->Additional Comment:
- Use `React.lazy` to dynamically import components only when needed.
- Wrap lazy-loaded components with `Suspense` to handle loading states.
- Consider using a tool like Webpack for code splitting to automatically split bundles.
- Analyze bundle size and loading times using tools like Webpack Bundle Analyzer.
- Ensure that lazy loading is applied to non-critical components to optimize user experience.
Recommended Links:
