Improve performance by compressing files in Azure Front Door

File compression is an effective method to improve file transfer speed and increase page-load performance. The compression reduces the size of the file before it's sent by the server. File compression can reduce bandwidth costs and provide a better experience for your users.

There are two ways to enable file compression:

  • Enabling compression on your origin server. Azure Front Door passes along the compressed files and delivers them to clients that request them.
  • Enabling compression directly on the Azure Front Door POP servers (compression on the fly). In this case, Azure Front Door compresses the files and sends them to the end users.

Note

Range requests may be compressed into different sizes. Azure Front Door requires the content-length values to be the same for any GET HTTP request. If clients send byte range requests with the accept-encoding header that leads to the Origin responding with different content lengths, then Azure Front Door will return a 503 error. You can either disable compression on Origin/Azure Front Door or create a Rules Set rule to remove accept-encoding from the request for byte range requests.

Important

Azure Front Door configuration changes takes up to 10 mins to propagate throughout the network. If you're setting up compression for the first time for your CDN endpoint, consider waiting 1-2 hours before you troubleshoot to ensure the compression settings have propagated to all the POPs.

Enabling compression

Note

In Azure Front Door, compression is part of Enable Caching in Route. Only when you Enable Caching, can you take advantage of compression in Azure Front Door.

You can enable compression in the following ways:

  • During quick create - When you enable caching, you can enable compression.
  • During custom create - Enable caching and compression when you're adding a route.
  • In Endpoint Manager route.
  • On the Optimization page.

Enable compression in Endpoint manager

  1. From the Azure Front Door Standard/Premium profile page, go to Endpoint Manager and select the endpoint you want to enable compression.

  2. Select Edit Endpoint, then select the route you want to enable compression.

    Screenshot of Endpoint Manager landing page.

  3. Ensure Enable Caching is checked, then select the checkbox for Enable compression.

    Enable compression in endpoint manager.

  4. Select Update to save the configuration.

Enable compression in Optimization

  1. From the Azure Front Door Standard/Premium profile page, go to Optimizations under Settings. Expand the endpoint to see the list of routes.

  2. Select the three dots next to the route that has compression Disabled. Then select Configure route.

    Screen of enable compression on the optimization page.

  3. Ensure Enable Caching is checked, then select the checkbox for Enable compression.

    Screen shot of enabling compression in endpoint manager.

  4. Click Update.

Modify compression content type

You can modify the default list of MIME types on Optimizations page.

  1. From the Azure Front Door Standard/Premium profile page, go to Optimizations under Settings. Then select the route that has compression Enabled.

  2. Select the three dots next to the route that has compression Enabled. Then select View Compressed file types.

    Screenshot of optimization page.

  3. Delete default formats or select Add to add new content types.

    Screenshot of customize file compression page.

  4. Select Save, to update compression configure .

Disabling compression

You can disable compression in the following ways:

  • Disable compression in Endpoint manager route.
  • Disable compression in Optimization page.

Disable compression in Endpoint manager

  1. From the Azure Front Door Standard/Premium profile page, go to Endpoint manager under Settings. Select the endpoint you want to disable compression.

  2. Select Edit Endpoint and then select the route you want to disable compression. Uncheck the Enable compression box.

  3. Select Update to save the configuration.

Disable compression in Optimizations

  1. From the Azure Front Door Standard/Premium profile page, go to Optimizations under Settings. Then select the route that has compression Enabled.

  2. Select the three dots next to the route that has compression Enabled, then select Configure route.

    Screenshot of disable compression in optimization page.

  3. Uncheck the Enable compression box.

    Screenshot of update route page for disabling compression.

  4. Select Update to save the configuration.

Compression rules

In Azure Front Door, only eligible files are compressed. To be eligible for compression, a file must:

  • Be of a MIME type
  • Be larger than 1 KB
  • Be smaller than 8 MB

These profiles support the following compression encodings:

  • gzip (GNU zip)
  • brotli

If the request supports more than one compression type, brotli compression takes precedence.

When a request for an asset specifies gzip compression and the request results in a cache miss, Azure Front Door does gzip compression of the asset directly on the POP server. Afterward, the compressed file is served from the cache.

If the origin uses Chunked Transfer Encoding (CTE) to send compressed data to the Azure Front Door POP, then response sizes greater than 8 MB aren't supported.

Next steps