Skip to content

Commit d24ed36

Browse files
feat(performance): optimize image loading and data fetching
- Change image loading strategy to 'eager' for initial batch - Load shared data after browser is idle to prioritize bandwidth - Preload additional font for Latin-1 Supplement characters
1 parent cde3980 commit d24ed36

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

app/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
<!-- Preload MonoLisa Basic Latin (most used, variable font = all weights) -->
3030
<link rel="preload" href="https://storage.googleapis.com/pyplots-static/fonts/0-MonoLisa-normal.woff2" as="font" type="font/woff2" crossorigin>
31+
<!-- Preload Latin-1 Supplement for ä, ö, ü, ß etc. -->
32+
<link rel="preload" href="https://storage.googleapis.com/pyplots-static/fonts/2-MonoLisa-normal.woff2" as="font" type="font/woff2" crossorigin>
3133

3234
<!-- JSON-LD Structured Data -->
3335
<script type="application/ld+json">

app/src/components/ImageCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export const ImageCard = memo(function ImageCard({
149149
>
150150
<CardMedia
151151
component="img"
152-
loading="lazy"
152+
loading={index < BATCH_SIZE ? 'eager' : 'lazy'}
153153
image={image.thumb || image.url}
154154
alt={viewMode === 'library' ? `${image.spec_id} - ${image.library}` : `${selectedSpec} - ${image.library}`}
155155
sx={{

app/src/components/Layout.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ export function AppDataProvider({ children }: { children: ReactNode }) {
3434
setHomeState((prev) => ({ ...prev, scrollY: window.scrollY }));
3535
}, []);
3636

37-
// Load shared data on mount
37+
// Load shared data after browser is idle — gives /plots/filter bandwidth priority
3838
useEffect(() => {
39-
const fetchData = async () => {
39+
const id = requestIdleCallback(async () => {
4040
try {
4141
const [specsRes, libsRes, statsRes] = await Promise.all([
4242
fetch(`${API_URL}/specs`),
@@ -61,8 +61,8 @@ export function AppDataProvider({ children }: { children: ReactNode }) {
6161
} catch (err) {
6262
console.error('Error loading initial data:', err);
6363
}
64-
};
65-
fetchData();
64+
});
65+
return () => cancelIdleCallback(id);
6666
}, []);
6767

6868
return (

0 commit comments

Comments
 (0)