Compression

This guide covers the Layer0 response compression support.

Accept-Encoding

When requesting data via HTTP from the Layer0 servers, browsers include the accept-encoding header to indicate which data compression formats the browser supports. Modern browsers accept multiple compression formats, Accept-Encoding Header Details are here. This header is required by Layer0 to trigger compression of responses.

Layer0 supports

  • gzip for all versions
  • br (Brotli) for versions >= 4.11.0

Enabling Brotli compression

To enable Brotli (br) compression you need to ensure your project uses a version of @layer0 >= 4.11.0. To upgrade @layer0 to the latest version in your project use 0 use latest and redeploy your project.

What is Compressed?

When Layer0 servers receive a request they inspect the accept-encoding header. The following logic is used to determine response compression:

  • If the response is not a compressible type, return uncompressed.
  • Else if br is found and the @layer0 version is >= 4.11.0 then compress the response using Brotli.
  • Else if gzip is found, then compress the response using gzip.
  • Else no compression is used.

Compressible Types

A response is considered compressible if the content-type contains one of these strings:

  • text/html
  • application/x-javascript
  • text/css
  • application/javascript
  • text/javascript
  • application/json
  • application/vnd.ms-fontobject
  • application/x-font-opentype
  • application/x-font-truetype
  • application/x-font-ttf
  • application/xml
  • font/eot
  • font/opentype
  • font/otf
  • image/svg+xml
  • image/vnd.microsoft.icon
  • text/plain
  • text/xml

or the url ends in one of these file extensions:

  • .css
  • .js
  • .html
  • .eot
  • .ico
  • .otf
  • .ttf
  • .json
  • .svg