Back
Web Fundamentals

Image & Video Optimization: Modern Formats & Techniques

Web Fundamentals
Build & Deployment: Monorepo, CI/CD, Strategies & Release SafetyState Management: Choosing the Right SolutionRedux: Predictable State Container (RTK + RTK Query)React Query (TanStack Query): Server State CachingData Fetching Patterns: REST, GraphQL, tRPC & Real-timeGraphQL Fundamentals for Frontend: Shape, Caching, and TradeoffsgRPC-Web Fundamentals: Browser Constraints and Proxy ModelCaching Strategies: Client, Server & EdgeData Normalization: Organizing State for PerformanceAPI Design Best Practices: Pagination, Errors, Versioning & Type SafetyAPI Versioning Strategies for Frontend CompatibilityPagination: Offset vs Cursor-BasedRate Limiting & API Resilience: Retries, Backoff, Jitter, IdempotencyHow Frontend Developers Can Handle Millions of API Requests Without Crashing EverythingBrowser Storage: Cookies, SessionStorage, LocalStorage, IndexedDBReal-time Communication: WebSockets, SSE & PollingWebRTC: Real-Time Communication in the BrowserCore Web Vitals: LCP, INP & CLSPerformance Optimization Trade-offsCritical Resource Prioritization: Optimize Loading OrderCode Splitting: Optimize Bundle Size with Dynamic ImportsTree Shaking: Eliminate Dead Code from Your BundleLazy Loading: Load Resources On-DemandResource Hints: Preload, Prefetch & PreconnectText Compression: Gzip and BrotliImage & Video Optimization: Modern Formats & TechniquesAdaptive Loading: Optimize for Device & NetworkList Virtualization: Render Large Lists EfficientlyWeb Workers vs Main Thread: Offloading Heavy WorkMemory Leaks in Frontend Apps: Detection & PreventionManaging Third-Party Scripts: Optimization StrategiesHow CDNs Work: Edge Delivery, Caching & PerformanceHTTP Caching Deep Dive: Cache-Control, ETag & RevalidationService Workers & Offline Strategy: Cache First, Network First & Update LifecyclePWA Fundamentals: Manifest, Installability & Offline UXCritical Rendering PathScript Loading: async vs deferEvent Loop: Understanding JavaScript Execution ModelJavaScript Module Systems: CJS vs ESM vs UMDDynamic Module Loading: import() FunctionImport on Interaction: Load When User InteractsImport on Visibility: Lazy Loading with IntersectionObserverBrowser Rendering Pipeline & Layout ThrashingRendering Strategies: CSR vs SSR vs SSG vs ISRStreaming SSR: Progressive HTML StreamingIslands Architecture: Independent Component HydrationReact Server Components: Zero-JS Server RenderingFramework Reactivity: React, Vue, Svelte & SolidHTTP/1.1 vs HTTP/2 vs HTTP/3 (QUIC) for Frontend PerformanceDNS Resolution: Path, TTL, Caching & Frontend ImpactCross-Site Scripting (XSS) AttacksCross-Site Request Forgery (CSRF) AttacksCORS Explained: Cross-Origin Resource SharingCORS Preflight in Practice: Credentials, Simple Requests & MisconfigurationsContent Security Policy (CSP)Why is HTTPS Secure? Understanding TLS/SSLAuthorization Best PracticesCookie Security & Session Hardening: SameSite, HttpOnly, Secure
easyPerformance

Image & Video Optimization: Modern Formats & Techniques

TL;DRUse WebP/AVIF + srcset + dimensions + lazy loading. Always reserve space to prevent CLS.
High Signal
Google
Meta
Netflix
Agoda
30-Second Answerstart every interview with this

Images and videos are often the largest resources on a page. Modern optimization techniques — next-gen formats, responsive delivery, lazy loading, and explicit dimensions — can reduce media size by 50-85% while improving LCP and eliminating layout shifts.

Instead of carrying one giant suitcase (full-size JPEG) for every trip (device), pack the right size for the journey (screen size), compress it efficiently (WebP/AVIF), and only open it when you arrive at the destination (lazy loading).

Choose Right Format (WebP/AVIF)
Serve Right Size (srcset)
Lazy Load Below Fold
Reserve Space (dimensions)

1Modern Image Formats

WebP offers ~30% savings over JPEG. AVIF offers even better compression. Always provide fallbacks with <picture>.

picture.htmlhtml
<picture>
  <source srcset="image.avif" type="image/avif">
  <source srcset="image.webp" type="image/webp">
  <img src="image.jpg" alt="Description" width="800" height="600">
</picture>

2Responsive Images & Lazy Loading

Use srcset + sizes for responsive delivery and loading="lazy" for below-the-fold images. Always set width/height or aspect-ratio.

3Video Optimization

Use WebM + MP4 with preload="metadata", lazy loading via poster, and facade patterns for third-party embeds like YouTube.

4Image CDNs & Automation

Tools like Next.js Image, Cloudinary, or Imgix handle format conversion, resizing, and optimization automatically.

PropertyJPEGWebPAVIF
SizeBaseline~30% smaller~50% smaller
ModernLegacy fallbackBroad supportGrowing support
QualityGood for photosExcellentBest

JPEG

Size

Baseline

Modern

Legacy fallback

Quality

Good for photos

WebP

Size

~30% smaller

Modern

Broad support

Quality

Excellent

AVIF

Size

~50% smaller

Modern

Growing support

Quality

Best

Common questions

  • ›“How do you optimize images for web performance?”
  • ›“Explain srcset and the picture element.”
  • ›“How do you prevent layout shift from images?”
  • ›“What is the difference between WebP and AVIF?”

What interviewers look for

  • Knowledge of modern formats and fallbacks
  • Understanding of responsive images and lazy loading
  • CLS prevention (dimensions, aspect-ratio)
  • Connection to Core Web Vitals (LCP/CLS)

Short answer (60 sec)

Use WebP/AVIF with <picture> fallbacks, srcset for responsive sizes, loading="lazy" for below-fold images, and always set explicit width/height to prevent CLS.

Detailed answer (senior level)

Modern image optimization combines next-gen formats (AVIF > WebP > JPEG), responsive delivery via srcset, lazy loading, and explicit dimensions. Use image CDNs for automation. For videos, use efficient codecs and facade patterns for embeds. These techniques directly improve LCP and eliminate CLS.

  • Serving full-size images to mobile devices
  • No dimensions on <img> tags (causes CLS)
  • Forgetting lazy loading on below-fold images
  • Using only one format without fallbacks
  • Compressing images at build time without CDN
Key Takeaways
  • ✓Use AVIF/WebP with proper fallbacks
  • ✓Implement srcset + sizes for responsive images
  • ✓Always set width/height or aspect-ratio
  • ✓Lazy load everything below the fold
  • ✓Use image CDNs for automatic optimization
  • ✓Measure impact on LCP and CLS
  • ✓Combine with code splitting for full wins
Previous TopicText Compression: Gzip and BrotliNext Topic Adaptive Loading: Optimize for Device & Network

On this page