Skip to content

Commit

Permalink
Lazily load viewer thumbnails (#240)
Browse files Browse the repository at this point in the history
* Add lazy load component and lazily load viewer thumbnail images

* Make prettier
  • Loading branch information
mikeapp authored Dec 16, 2024
1 parent f8a60d3 commit 9164efb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"react-dom": "^18.3.1",
"react-error-boundary": "^4.1.2",
"react-i18next": "^15.1.1",
"react-lazy-load-image-component": "^1.6.2",
"sanitize-html": "^2.13.1",
"swiper": "^9.0.0",
"uuid": "^9.0.1"
Expand Down
9 changes: 8 additions & 1 deletion src/components/Viewer/Media/Thumbnail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Label } from "src/components/Primitives";
import React from "react";
import { convertTime } from "src/lib/utils";
import { getLabel } from "src/hooks/use-iiif";
import { LazyLoadImage } from "react-lazy-load-image-component";

/**
* Determine appropriate icon by resource type
Expand Down Expand Up @@ -69,7 +70,13 @@ const Thumbnail: React.FC<ThumbnailProps> = ({
>
<figure>
<div>
{thumbnail?.id && <img src={thumbnail.id} alt={label as string} />}
{thumbnail?.id && (
<LazyLoadImage
src={thumbnail.id}
alt={label as string}
loading="lazy"
/>
)}

<Type>
<Tag isIcon data-testid="thumbnail-tag">
Expand Down

0 comments on commit 9164efb

Please sign in to comment.