Skip to content

Commit 379f0f5

Browse files
Optimize bundle size with code splitting - reduce main bundle by 25%
- Implement lazy loading for all pages (Login, Register, Dashboard, Project, Archive) - Add Suspense with LoadingSpinner fallback during page load - Main bundle reduced: 503KB → 375KB (-128KB, -25%) - Gzipped main bundle: 150KB → 118KB (-31KB, -21%) - Pages now load on-demand for faster initial load time - Fixes Vite chunk size warning
1 parent 1ca3a7a commit 379f0f5

1 file changed

Lines changed: 22 additions & 17 deletions

File tree

frontend/src/App.tsx

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import React, { useMemo } from 'react';
2+
import React, { useMemo, lazy, Suspense } from 'react';
33
import {
44
ApolloClient,
55
InMemoryCache,
@@ -9,15 +9,18 @@ import {
99
import { setContext } from '@apollo/client/link/context';
1010
import { ApolloProvider } from '@apollo/client/react';
1111
import { BrowserRouter, Routes, Route } from 'react-router-dom';
12-
import Login from './pages/Login';
13-
import Register from './pages/Register';
14-
import Dashboard from './pages/Dashboard';
15-
import Project from './pages/Project';
16-
import Archive from './pages/Archive';
1712
import { AuthProvider, useAuth } from './context/AuthContext';
1813
import { ThemeProvider } from './context/ThemeContext';
1914
import ProtectedRoute from './components/ProtectedRoute';
2015
import ErrorBoundary from './components/ErrorBoundary';
16+
import LoadingSpinner from './components/LoadingSpinner';
17+
18+
// Lazy load pages for code splitting
19+
const Login = lazy(() => import('./pages/Login'));
20+
const Register = lazy(() => import('./pages/Register'));
21+
const Dashboard = lazy(() => import('./pages/Dashboard'));
22+
const Project = lazy(() => import('./pages/Project'));
23+
const Archive = lazy(() => import('./pages/Archive'));
2124

2225
const AppContent: React.FC = () => {
2326
const { token } = useAuth();
@@ -64,17 +67,19 @@ const AppContent: React.FC = () => {
6467
return (
6568
<ApolloProvider client={client}>
6669
<BrowserRouter>
67-
<Routes>
68-
<Route path="/" element={<Login />} />
69-
<Route path="/login" element={<Login />} />
70-
<Route path="/register" element={<Register />} />
71-
<Route element={<ProtectedRoute />}>
72-
<Route path="/dashboard" element={<Dashboard />} />
73-
<Route path="/project/:id" element={<Project />} />
74-
<Route path="/archive" element={<Archive />} />
75-
</Route>
76-
<Route path="*" element={<Login />} />
77-
</Routes>
70+
<Suspense fallback={<LoadingSpinner />}>
71+
<Routes>
72+
<Route path="/" element={<Login />} />
73+
<Route path="/login" element={<Login />} />
74+
<Route path="/register" element={<Register />} />
75+
<Route element={<ProtectedRoute />}>
76+
<Route path="/dashboard" element={<Dashboard />} />
77+
<Route path="/project/:id" element={<Project />} />
78+
<Route path="/archive" element={<Archive />} />
79+
</Route>
80+
<Route path="*" element={<Login />} />
81+
</Routes>
82+
</Suspense>
7883
</BrowserRouter>
7984
</ApolloProvider>
8085
);

0 commit comments

Comments
 (0)