Skip to content

Open source CapCut alternative.

TypeScript

perf(site): eager-load first-row showcase images for LCP

David Lefa6fec3fe421
diff --git a/site/src/app/_components/landing/media-showcase/MediaCard.tsx b/site/src/app/_components/landing/media-showcase/MediaCard.tsx
index a55f52e3..c6191861 100644
--- a/site/src/app/_components/landing/media-showcase/MediaCard.tsx
+++ b/site/src/app/_components/landing/media-showcase/MediaCard.tsx
@@ -27,6 +27,8 @@ export function layoutRatio(item: MediaShowcaseItem): number {
type Props = {
item: MediaShowcaseItem;
onOpen: (item: MediaShowcaseItem) => void;
+ // Above-the-fold tile: preload its image eagerly (it is a likely LCP).
+ priority?: boolean;
// Flex sizing from the row packer: grow shares row width by aspect ratio so
// tiles in a row end up the same height; a sparse last row passes grow 0
// with a fixed pixel basis instead.
@@ -43,7 +45,13 @@ type Props = {
// every tile in a flex row ends up the same height and each row fills the full
// width — landscape rows come out short, vertical-video rows tall. The row
// height scale lives in the grid container's --row-h variable.
-export function MediaCard({ item, onOpen, pack, uniformGrid = false }: Props) {
+export function MediaCard({
+ item,
+ onOpen,
+ pack,
+ priority = false,
+ uniformGrid = false,
+}: Props) {
const isVideo = item.kind === "video";
const KindIcon = isVideo ? Film : ImageIcon;
const ratio = uniformGrid ? tileRatio(item) : layoutRatio(item);
@@ -89,6 +97,7 @@ export function MediaCard({ item, onOpen, pack, uniformGrid = false }: Props) {
alt={item.title}
className="object-cover transition-transform duration-300 group-hover:scale-[1.03]"
fill
+ priority={priority}
sizes="(max-width: 640px) 100vw, (max-width: 1024px) 50vw, 33vw"
src={item.thumbnailSrc}
/>
diff --git a/site/src/app/_components/landing/media-showcase/MediaShowcase.tsx b/site/src/app/_components/landing/media-showcase/MediaShowcase.tsx
index 47a4c5f9..8228b4db 100644
--- a/site/src/app/_components/landing/media-showcase/MediaShowcase.tsx
+++ b/site/src/app/_components/landing/media-showcase/MediaShowcase.tsx
@@ -159,6 +159,7 @@ export function MediaShowcase({ blurb, heading }: Props) {
item={item}
key={item.id}
onOpen={setSelected}
+ priority={rowIndex === 0}
pack={
stretch
? { grow: layoutRatio(item), basis: "0px" }
@@ -177,11 +178,12 @@ export function MediaShowcase({ blurb, heading }: Props) {
// Uniform column grid for all-vertical sets, and the pre-measure
// fallback frame for the packed layout's first paint.
<div className="flex flex-wrap gap-4 [--row-h:180px] after:grow-[9999] after:content-[''] sm:[--row-h:220px] lg:[--row-h:260px] xl:[--row-h:320px] 2xl:[--row-h:400px]">
- {items.map((item) => (
+ {items.map((item, index) => (
<MediaCard
item={item}
key={item.id}
onOpen={setSelected}
+ priority={index < 5}
uniformGrid={uniformGrid}
/>
))}