Skip to content

feat(gallery): serve event images through Vercel's image optimizer#181

Draft
rayhanadev wants to merge 2 commits into
mainfrom
ray/optimize-images
Draft

feat(gallery): serve event images through Vercel's image optimizer#181
rayhanadev wants to merge 2 commits into
mainfrom
ray/optimize-images

Conversation

@rayhanadev

Copy link
Copy Markdown
Member

Summary

  • Enable Vercel's imageService in @astrojs/vercel, allow-list cms.purduehackers.com in imagesConfig, so /_vercel/image?url=…&w=…&q=… is served on our domain.
  • Tiny helper src/utilities/image.ts (optimizedUrl, optimizedSrcset) that wraps remote Payload URLs through the optimizer.
  • Gallery.astro: precompute thumbnail + lightbox src/srcset pairs in the server frontmatter and pass them into the client script. Thumbnails use widths [400, 800, 1200]; lightbox uses [800, 1200, 1600, 2400]. Offscreen tiles get loading="lazy" (first three stay eager), and width/height are threaded through Payload's media metadata so browsers reserve space and stop layout-shifting.
  • [event].astro: forward image.width / image.height from Payload into the Gallery props.

Why

Event pages currently ship multi-MB full-resolution originals for every image. Lighthouse flags both the transfer size and layout shift.

Test plan

  • pnpm install && pnpm build clean
  • Inspect DevTools Network on a populated past-event page: <img> requests hit /_vercel/image?url=… not raw cms.purduehackers.com/api/media/file/…, transfer sizes in the low hundreds of KB, Content-Type is image/webp (or AVIF)
  • Lightbox navigates between images; preloads use the optimized URL
  • Click a grid thumbnail → lightbox shows a higher-resolution variant

🤖 Generated with Claude Code

Before: event galleries rendered raw Payload media URLs in <img> tags,
shipping multi-MB originals to every visitor with no width/height, no
srcset, no lazy loading.

Changes:
- astro.config.mjs: enable Vercel's imageService and allowlist the CMS
  domain in imagesConfig so /_vercel/image?url=...&w=... is served.
- src/utilities/image.ts: small helpers (`optimizedUrl`, `optimizedSrcset`)
  that wrap a remote Payload URL through the Vercel optimizer.
- Gallery.astro: precompute thumb + lightbox src/srcset pairs in the
  server frontmatter, pass them into the client via define:vars, use
  them when building the grid and lightbox <img>s. Adds loading=lazy
  for offscreen tiles, eager for the first three. Passes through
  width/height so browsers reserve space and stop layout-shifting.
- [event].astro: forward Payload's `image.width` / `image.height` into
  the Gallery props.

Net effect per image on wire: multi-MB original -> tens or low hundreds
of KB resized WebP/AVIF, with responsive srcset at 400/800/1200 for
thumbs and 800/1200/1600/2400 for lightbox.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 21, 2026 03:51
@vercel

vercel Bot commented Apr 21, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
events Ready Ready Preview, Comment Apr 21, 2026 4:01am

Request Review

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enables serving event gallery images through Vercel’s on-demand image optimizer to reduce transfer size and layout shift on event pages.

Changes:

  • Added image URL helpers (optimizedUrl, optimizedSrcset) to wrap remote CMS images through /_vercel/image.
  • Updated the Gallery component to precompute optimized thumbnail/lightbox src + srcset values and thread through width/height + lazy-loading behavior.
  • Enabled Vercel image service and allow-listed cms.purduehackers.com in Astro/Vercel configuration.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/utilities/image.ts Adds helper functions to generate optimizer URLs and srcsets for remote images.
src/pages/events/[event].astro Passes through image width/height metadata from Payload into Gallery props.
src/components/past-events/Gallery.astro Uses optimized URLs/srcsets for thumbnails + lightbox, sets loading/decoding, and applies width/height.
astro.config.mjs Enables Vercel image service and configures allowed remote image domain/sizes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/components/past-events/Gallery.astro Outdated
Comment thread src/components/past-events/Gallery.astro Outdated
Comment thread src/components/past-events/Gallery.astro
Comment thread src/components/past-events/Gallery.astro Outdated
- Drop the `.ts` extension from the image-utilities import so it matches
  the rest of the repo (allowImportingTsExtensions is off).
- Set `srcset`/`sizes` before `src` on the lightbox and grid <img>
  elements so the browser doesn't kick off a fetch for the `src` URL
  before the srcset picker runs. Also shrink both `src` fallbacks to
  the smallest candidate width (the first entry of each widths array)
  so a legacy client without srcset support pulls the smallest image.
- Simplify the thumbnail `loading` ternary: `isHidden || i >= 3` was
  redundant since `isHidden` is already `i >= 3`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

@ericswpark ericswpark left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but will wait on @lilianzlettuce 's review

@rayhanadev rayhanadev marked this pull request as draft April 21, 2026 18:30
@rayhanadev

Copy link
Copy Markdown
Member Author

Making this a draft while I finalize CMS move to Vercel, will re-open after. Code should be same but domains may change and such.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants