Conceptual
2 min read

How Compression Works for the Edge Network

Vercel helps reduce data transfer and improve performance by supporting both gzip and brotli compression
Table of Contents

Vercel helps reduce data transfer and improve performance by supporting both gzip and brotli compression. These algorithms are widely used to compress files, such as HTML, CSS, and JavaScript, to reduce their sizes.

While gzip has been around for quite some time, brotli is a newer compression algorithm built by Google that best serves text compression. If your client supports brotli, it's recommended over gzip because:

  • brotli compressed JavaScript files are 14% smaller than gzip
  • HTML files are 21% smaller than gzip
  • CSS files are 17% smaller than gzip

brotli has an advantage over gzip since it uses a dictionary of common keywords on both the client and server-side, which gives a better compression ratio.

Many clients (e.g., browsers like Chrome, Firefox, and Safari) include the Accept-Encoding request header by default. This automatically enables compression for Vercel's Edge Network.

The following clients may not include the Accept-Encoding header by default:

  • Custom applications, such as Python scripts, Node.js servers, or other software that can send HTTP requests to your deployment
  • HTTP libraries, such as http in Node.js, and networking tools, like curl or wget
  • Older browsers. Check MDN's browser compatibility list to see if your client supports Accept-Encoding by default
  • Bots and crawlers sometimes do not specify Accept-Encoding in their headers by default when visiting your deployment

You will need to set the Accept-Encoding header in your code to opt into compression.

Vercel's Edge Network regularly maintains a configuration file for the MIME types that will be compressed for both gzip and brotli:

  • json
  • x-web-app-manifest+json
  • geo+json
  • manifest+json
  • ld+json
  • atom+xml
  • rss+xml
  • xhtml+xml
  • xml
  • rdf+xml
  • javascript
  • vnd.ms-fontobject
  • wasm
  • otf
  • svg+xml
  • bmp
  • cache-manifest
  • css
  • dns
  • javascript
  • plain
  • markdown
  • vcard
  • calendar
  • vnd.rim.location.xloc
  • vtt
  • x-component
  • x-cross-domain-policy
Last updated on June 20, 2024