layer5 icon indicating copy to clipboard operation
layer5 copied to clipboard

[Performance] Convert oversized GIFs to video to cut ~56 MB of first-load image payload across product pages

Open ayushgade06 opened this issue 2 months ago • 4 comments

Summary

Replaces large animated GIFs across the Layer5 website with optimized MP4/WebM videos to reduce page weight, unnecessary downloads, and rendering overhead.

There are currently 31 referenced GIFs totaling 61.15 MB. They are served as raw <img> elements and are not processed by gatsby-plugin-image, so Gatsby copies the .gif files into /public as-is, with no compression, resizing, or modern format. None use loading="lazy".

Problem

Several product pages load multiple large GIFs at once, so a lot of media is downloaded during the initial page load.

Measured GIF payload by page:

Page GIFs Payload
/cloud-native-management/kanvas/design 4 11.55 MB
/blog/kanvas/what-is-the-kanvas-catalog 2 10.57 MB
/cloud-native-management/generate-aws-architecture-diagram 4 9.11 MB
/cloud-native-management/meshery/ 5 7.77 MB
/cloud-native-management/generate-gcp-architecture-diagram 2 7.20 MB
/solutions/architecture-diagram/ 4 5.65 MB
/cloud-native-management/generate-kubernetes-architecture-diagram 4 4.74 MB
/solutions/orchestration-management/ 4 2.47 MB
/projects/cloud-native-performance 1 1.05 MB
/solutions/platform-engineering/ 1 1.04 MB

Sizes are measured from the source assets in decimal MB, matching how browser DevTools and PageSpeed report transfer sizes.

On the Kanvas Design page, all four carousel GIFs (11.55 MB) are statically imported and rendered on mount; inactive slides are only hidden with CSS visibility: hidden, which does not stop the browser downloading them. The same four GIFs are also imported again by the mobile swiper (duplicated references).

Root Cause

GIF is inefficient for UI and screen-recording content: limited to 256 colors and without the inter-frame compression of modern codecs, so short recordings become several MB. The same content as H.264 MP4 or VP9 WebM is typically much smaller. There is also no consistent lazy-loading strategy today, and the Kanvas carousel has its width/height commented out.

Changes

GIF to MP4/WebM

Large animated GIFs are replaced with optimized MP4/WebM equivalents.

Lazy media loading

preload="none" alone is not enough: an autoplaying <video> overrides preload and fetches on mount, just like the GIFs. Deferral is handled with an IntersectionObserver that gates both loading and playback. The real source is attached and playback started only when the element is near the viewport, and paused when it scrolls away.

Accessibility and motion control

The shared video component:

  • Respects prefers-reduced-motion: reduce: no autoplay, shows the poster frame with click-to-play.
  • Exposes a visible pause/play control, satisfying WCAG 2.2.2 (Pause, Stop, Hide).

Kanvas carousel

Duplicate GIF imports between the desktop carousel and mobile swiper are removed so both reference the same optimized sources.

Layout stability

Replacement videos use explicit width/height or an aspect-ratio so swapping in videos does not introduce layout shift.

Impact

Referenced animated media drops from 61.15 MB to roughly 5 MB, with less main-thread work from continuous GIF decode/repaint since video is composited by the browser. The existing visual experience is preserved.

ayushgade06 avatar Sep 27 '26 06:09 ayushgade06

can i take that issue? @ayushgade06

Jignesh4611 avatar Sep 27 '26 11:09 Jignesh4611

Hey @Jignesh4611, thanks for asking! I plan to take this one up myself, but if I run into any blockers, I’ll definitely ping you. Appreciate it!

Could you assign me this issue @PARTH-TUSSLE @Maanvi212006

ayushgade06 avatar Sep 27 '26 11:09 ayushgade06

Converting those oversized GIFs to video should noticeably cut the first-load payload. I would like to help. Assign me?

tanav29 avatar Oct 03 '26 17:10 tanav29

Hi team! 👋

I would love to tackle this optimization. I can convert the oversized animation assets to compressed web formats/video components across the product pages to significantly reduce first-load bundle size and improve page load metrics.

Could you please assign this to me?

VimalN2005 avatar Oct 16 '26 08:10 VimalN2005