From a002bfb136ec912bf06712049fbf3dcd9f8fcf1a Mon Sep 17 00:00:00 2001
From: Thor Tveito
Date: Mon, 12 Oct 2026 12:30:34 +0200
Subject: [PATCH 1/2] Perf: Lazy-load secondary pages and the Leaflet map
Load the detail and submit pages with React.lazy, so only the landing
page is in the first download. Lazy-load the map in the result list
too, with a placeholder of the same size, so the text of the results
renders before Leaflet arrives.
JavaScript needed before the first render goes from 636.65 kB
(196.43 kB gzip) to 464.62 kB (143.93 kB gzip), and the Vite warning
about chunks over 500 kB is gone. The landing page still fetches
Leaflet (49.92 kB gzip) for the map thumbnails, but after first render.
Refs #55
Co-Authored-By: Claude Opus 5.5
---
frontend/src/App.tsx | 20 +++++++++++++-------
frontend/src/components/SightingList.css | 4 ++++
frontend/src/components/SightingList.tsx | 19 +++++++++++++++++--
frontend/src/tests/SightingList.test.tsx | 5 +++--
4 files changed, 37 insertions(+), 11 deletions(-)
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index 468e4c1..0ba3a2e 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -1,21 +1,27 @@
+import { lazy, Suspense } from 'react'
import { Route, Routes } from 'react-router'
import BackendStatus from './components/BackendStatus'
import Banner from './components/Banner'
import SearchPage from './pages/SearchPage'
-import SightingDetailPage from './pages/SightingDetailPage'
-import SubmitSightingPage from './pages/SubmitSightingPage'
import './App.css'
+// Only the landing page is in the first download. The other pages are
+// fetched when their route is first visited, including by direct link.
+const SightingDetailPage = lazy(() => import('./pages/SightingDetailPage'))
+const SubmitSightingPage = lazy(() => import('./pages/SubmitSightingPage'))
+
function App() {
return (
<>
-
- } />
- } />
- } />
-
+ Loading…