Skip to content

Commit

Permalink
perf: add lazy loading for images and video elements
Browse files Browse the repository at this point in the history
  • Loading branch information
KnownBlackHat committed Sep 17, 2023
1 parent 019918b commit 01bb875
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/components/MediaCard.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useRef } from "react";

export default function MediaCard (props) {
const { image, media, headline, newslink, speed } = props
const video = useRef();
Expand Down Expand Up @@ -60,7 +61,7 @@ export default function MediaCard (props) {
{media ?
<>
<div className="flex justify-end"> <span className="bg-red-600 absolute rounded p-1 text-xs"> Video </span> </div>
<video defer ref={video}
<video loading="lazy" defer ref={video}
preload="auto"
onError={handleVideoError}
loop
Expand All @@ -69,6 +70,7 @@ export default function MediaCard (props) {
className="rounded h-[15em] w-[100%] bg-black" src={media} alt="Failed to load" /></>
:
<div className="bg-black inset-0"> <img
loading="lazy"
preload="auto" defer
onClick={handleClickImage}

Expand Down

0 comments on commit 01bb875

Please sign in to comment.