Frontend School
DashboardProblemsLearnPracticeMock InterviewReportsStatsBuy Credits
DashboardProblemsLearnPracticeMock Interview
Frontend System Design Roadmap
  1. 1.HTTP/1.1 vs HTTP/2 vs HTTP/3 (QUIC)
  2. 2.TCP and TLS Handshakes: Connection Setup Costs
  3. 3.Browser Network Stack and Connection Pooling
  4. 4.GET vs POST and Idempotency in HTTP
  5. 5.The Critical Rendering Path (CRP)
  6. 6.DOM, CSSOM and the Render Tree
  7. 7.Layout, Paint and Compositing
  8. 8.Reflows and Repaints Explained
  9. 9.Event Loop: Call Stack, Task and Microtask Queues
  10. 10.Async JavaScript: Promises and async/await
  11. 11.Web Workers: Multi-threading in the Browser
  12. 12.Browser Storage: Cookies, Web Storage, IndexedDB
  13. 13.Client-Side Storage: Limits and Security Risks
  14. 14.Choosing the Right Client-Side Storage
  15. 15.HTTP Caching: Cache-Control, ETag, Last-Modified
  16. 16.Browser-Level Caching Mechanisms
  17. 17.Cache Invalidation for Frontend Apps
  18. 18.Structuring a Large Single-Page App
  19. 19.Component-Based Architecture Principles
  20. 20.Props, State and Component Lifecycle
  21. 21.Module Bundling Basics
  22. 22.Core Web Vitals: LCP, INP and CLS
  23. 23.FCP and Time to Interactive (TTI) Explained
  24. 24.Measuring Performance: Lighthouse and WebPageTest
  25. 25.Asset Compression and Minification Basics
  26. 26.What Is a CDN and How Does It Work?
  27. 27.CDN Benefits: Latency, Availability, Offload
  28. 28.CDN Cache Behavior and Invalidation
  29. 29.Global State vs Local Component State
  30. 30.State Patterns: Redux, Zustand and Context
  31. 31.Data Fetching: React Query and SWR
  32. 32.Immutable Data in Frontend State
  33. 33.SSR vs CSR: Rendering Trade-offs
  34. 34.Hydration and Time to First Byte (TTFB)
  35. 35.Static Site Generation (SSG) for Speed and SEO
  36. 36.Incremental Static Regeneration (ISR)
  37. 37.Micro-Frontends: Core Principles
  38. 38.Micro-Frontend Integration Strategies
  39. 39.Communication Between Micro-Frontends
  40. 40.Micro-Frontends: Pros and Cons for Large Teams
  41. 41.Real-Time: Polling, SSE and WebSockets
  42. 42.Real-Time Use Cases: Chat, Alerts, Live Data
  43. 43.Designing a Real-Time Data Flow
  44. 44.Scaling WebSocket Connections
  45. 45.Responsive Images: srcset, sizes and picture
  46. 46.Modern Image Formats: WebP, AVIF, JPEG XL
  47. 47.Lazy Loading Images and Videos
  48. 48.Video Streaming: HLS, DASH, Adaptive Bitrate
  49. 49.REST and GraphQL for Frontend Engineers
  50. 50.Batching, Throttling and Debouncing API Calls
  51. 51.Handling API Errors in the Frontend
  52. 52.Authentication Flows: OAuth and JWT
  53. 53.Global Error Boundaries in React
  54. 54.Error Reporting: Sentry and LogRocket
  55. 55.Graceful Degradation and Fallback UIs
  56. 56.Real User Monitoring (RUM)
  57. 57.CORS: Cross-Origin Resource Sharing
  58. 58.Preventing XSS (Cross-Site Scripting)
  59. 59.CSRF Protection for Frontend Apps
  60. 60.Content Security Policy (CSP)
  61. 61.Storing Auth Tokens: Cookies vs localStorage
  62. 62.PWA Manifest and Installability
  63. 63.Service Workers: Lifecycle and Caching Strategies
  64. 64.Offline Support and Background Sync
  65. 65.Push Notifications for Web Apps
  66. 66.Webpack vs Vite vs Parcel
  67. 67.Code Splitting, Tree Shaking, Asset Optimization
  68. 68.Module Resolution and Hot Module Replacement
  69. 69.Monorepo Tooling: Nx and Lerna
  70. 70.Atomic Design for Component Libraries
  71. 71.Theming and Customization in Design Systems
  72. 72.Accessibility in Component Libraries
  73. 73.Component Library Docs, Testing and Versioning
  74. 74.Publishing and Consuming a Component Library
  75. 75.Full-Text Search: Levenshtein and Fuzzy Matching
  76. 76.Indexing Large Datasets in the Browser
  77. 77.Search Performance: Debouncing and Web Workers
  78. 78.Integrating Backend Search Services
  79. 79.Choosing a Chart Library: D3, Chart.js, Recharts
  80. 80.Rendering Large Datasets: Canvas vs SVG
  81. 81.Interactive, Responsive Data Visualizations
  82. 82.Data Fetching and Aggregation for Dashboards
  83. 83.A/B Test Design and Rollout Strategies
  84. 84.Client-Side vs Server-Side A/B Testing
  85. 85.Feature Flags and Remote Configuration
  86. 86.Experiment Data Collection and Analytics
Frontend System Design Roadmap
46

Frontend System Design · Lesson 46 of 86 · 4 min

Modern Image Formats: WebP, AVIF, JPEG XL

This is a classic performance optimization question. Knowing the trade-offs shows you can build fast websites, not just functional ones.

The core trade-off: file size vs. quality

For years, we've balanced JPEG's lossy compression for photos against PNG's lossless quality for graphics. This is a false dichotomy now. Modern formats like WebP and AVIF offer much better compression, meaning you can get higher quality images for significantly smaller file sizes.

WebP typically creates files 25-35% smaller than an equivalent quality JPEG. AVIF can be 30-50% smaller than WebP. These savings directly reduce page load time and data usage, which are critical for Largest Contentful Paint (LCP) and user experience on mobile.

These formats aren't just smaller. They also support features that required separate formats before, like alpha transparency (like PNG) and animation (like GIF), all in one package.

Your modern image toolbox: WebP, AVIF, JPEG XL

In an interview, you need to know the specific use case for each. Don't just say "they're smaller."

WebP: This is your baseline modern format. It has near-universal support across modern browsers and has been around long enough to be stable and well-supported by tooling. It offers both lossy and lossless compression. If you can only support one modern format, this is it.

AVIF: This is your high-performance option. Based on the AV1 video codec, it provides the best compression available in browsers today. It also supports modern features like HDR and wide color gamuts. Use it for hero images, product photos, or any visually critical content where you need the absolute smallest file size for a given quality level.

The trap: Browser support for AVIF is good, but not as universal as WebP. You can't serve only AVIF. It must be part of a fallback strategy.

JPEG XL: This is the one to watch. Its killer feature is the ability to losslessly re-compress existing JPEGs, reducing their size by ~20% without any quality degradation. This is a massive advantage for migrating large, existing image libraries. It also has excellent compression and progressive rendering.

The interview landmine: As of late 2023, Chrome removed support for JPEG XL, and no major browser supports it by default. Mentioning it shows you're knowledgeable about the future of image formats, but presenting it as a solution you'd implement today is a red flag. Frame it as something to keep an eye on for future-proofing a system.

Your decision flow should be: serve AVIF if possible, fall back to WebP, and finally fall back to the original JPEG or PNG.

How to serve modern formats without breaking old browsers

You don't use JavaScript user-agent sniffing. You use the <picture> element to let the browser choose for itself.

This is the standard, declarative way to provide multiple formats. The browser works down the list of <source> elements and picks the first one it supports based on the type attribute. If it supports none, it uses the <img> tag as a final fallback.

<picture>
  <!-- The browser will check for AVIF support first. -->
  <source srcset="image.avif" type="image/avif" />
  
  <!-- If it doesn't support AVIF, it checks for WebP. -->
  <source srcset="image.webp" type="image/webp" />
  
  <!-- The img tag is the final fallback for all other browsers. -->
  <img src="image.jpg" alt="A description of the image." width="800" height="600" />
</picture>

In an interview, you should be able to write this <picture> block from memory. It's fundamental. Also, be sure to mention that you'd include width and height attributes on the <img> tag to prevent Cumulative Layout Shift (CLS). This shows you're thinking about the full picture of web performance, not just asset size.

This pattern is combined with the srcset and sizes attributes (covered in the previous lesson) to handle responsive images and multiple formats simultaneously.

The backend: Where do these images come from?

You don't manually create three formats and multiple sizes for every image. This process must be automated. In a system design interview, this is the part you'll spend more time on.

The images are generated in a pipeline, which can be triggered either at build time or on-the-fly.

There are two common architectures for this:

  1. Build-Time Generation: Frameworks like Next.js (with next/image) or static site generators can process local images during the build. They generate the required formats and sizes, which are then deployed with your static assets. This is great for sites where the images don't change often, like a marketing page or blog.

  2. On-the-Fly Transformation (Image CDNs): For sites with user-generated content or massive image libraries (e-commerce, social media), you upload one high-resolution original. An image CDN service (like Cloudinary, Imgix, or self-hosted solutions) then creates different versions dynamically on request. The URL itself specifies the transformations, like .../image.jpg?format=avif&width=800. The CDN heavily caches these transformed images so they are only generated once.

Knowing the difference between these two approaches is key. The build-time approach is simpler and has no runtime cost, but is inflexible. The dynamic approach is powerful and scalable, but adds a service dependency and cost.

Try it

Take a high-quality JPEG from one of your projects (at least 1MB). Use an online tool like Squoosh to convert it to WebP and AVIF. Adjust the quality slider for each to find the point where they are visually indistinguishable from the original JPEG. Note the file size difference. Then, create a local HTML file with the <picture> element to serve all three versions and test it in your browser's network tab.

Next: We'll cover how to stop loading images until they're actually needed in Lazy Loading Images and Videos.

Lock it in — apply this lesson under interview conditions.

Try a free mock interviewPractice system design problems
Previous

Responsive Images: srcset, sizes and picture

Next

Lazy Loading Images and Videos