Skip to content

Commit 9164efb

Browse files
authored
Lazily load viewer thumbnails (#240)
* Add lazy load component and lazily load viewer thumbnail images * Make prettier
1 parent f8a60d3 commit 9164efb

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

package-lock.json

+23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
"react-dom": "^18.3.1",
9696
"react-error-boundary": "^4.1.2",
9797
"react-i18next": "^15.1.1",
98+
"react-lazy-load-image-component": "^1.6.2",
9899
"sanitize-html": "^2.13.1",
99100
"swiper": "^9.0.0",
100101
"uuid": "^9.0.1"

src/components/Viewer/Media/Thumbnail.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { Label } from "src/components/Primitives";
1414
import React from "react";
1515
import { convertTime } from "src/lib/utils";
1616
import { getLabel } from "src/hooks/use-iiif";
17+
import { LazyLoadImage } from "react-lazy-load-image-component";
1718

1819
/**
1920
* Determine appropriate icon by resource type
@@ -69,7 +70,13 @@ const Thumbnail: React.FC<ThumbnailProps> = ({
6970
>
7071
<figure>
7172
<div>
72-
{thumbnail?.id && <img src={thumbnail.id} alt={label as string} />}
73+
{thumbnail?.id && (
74+
<LazyLoadImage
75+
src={thumbnail.id}
76+
alt={label as string}
77+
loading="lazy"
78+
/>
79+
)}
7380

7481
<Type>
7582
<Tag isIcon data-testid="thumbnail-tag">

0 commit comments

Comments
 (0)