Content Delivery
Gzip/Brotli compression, image optimization (WebP, AVIF), minification
Content delivery optimization reduces the size and transmission time of HTTP responses through compression, modern image formats, and asset minification. Brotli compression (RFC 7932) achieves 20–26% better compression ratios than Gzip for text assets at the same CPU cost, and is supported by all modern browsers. WebP provides 25–34% smaller images than JPEG/PNG at equivalent quality; AVIF (AV1 Image Format) provides 50% smaller files than JPEG. These techniques directly impact Core Web Vitals scores (LCP, CLS) and Google search ranking.
Key Points
- Brotli compression: 20–26% better than Gzip for HTML/CSS/JS; requires HTTPS (only served over secure connections); Nginx: `brotli on; brotli_comp_level 6;`.
- Gzip: fallback for older clients and non-text content; enable with `Content-Encoding: gzip`; level 6 is sweet spot of compression ratio vs. CPU cost.
- WebP: 25–34% smaller than JPEG/PNG; supported by all modern browsers; serve via `<picture>` element with JPEG/PNG fallback for older browsers.
- AVIF: next-gen format with 50% smaller files than JPEG using AV1 codec; Chrome 85+, Firefox 93+, Safari 16+; slower to encode but worth it for static assets.
- Minification: remove whitespace, comments, and shorten identifiers in JS/CSS — Terser (JS), cssnano (CSS), html-minifier reduce asset sizes 20–40%.
- Tree shaking: remove unused JavaScript exports at bundle time — Rollup and Webpack 5 eliminate dead code, cutting bundle size 30–60% for large libraries.
- Code splitting: lazy-load route components and below-fold features — reduces initial bundle from 1MB to <200KB, directly improving Time to Interactive (TTI).
- Sprite sheets and icon fonts vs. SVGs: inline SVGs are preferred for icons — eliminate HTTP requests, style with CSS, scale perfectly, smaller total payload.
Real-World Example
Etsy's performance team reduced image payload by 70% by migrating to WebP with AVIF for supported browsers, and implementing responsive images (`srcset`) to serve appropriately-sized images per device. Combined with Brotli compression, their LCP improved from 4.2s to 1.8s, lifting conversion rate by 12%.