---
name: azion-compress-application-responses-with-gzip
description: >-
  Create a Rules Engine rule that compresses the responses of an application with gzip, and look up the MIME types that Azion compresses.
---

# Compress application responses with gzip

You can compress the responses of an [application](/en/documentation/platform/applications/) with gzip from Azion Console, with a rule in [Rules Engine for Applications](/en/documentation/platform/applications/rules-engine/).

Gzip is the standard method of lossless file compression for web applications. It uses the Deflate algorithm to reduce the size of a file before the file reaches the browser. Pages then render and download faster. For more about the format, refer to the [gzip website](https://www.gzip.org/).

When a rule with the gzip behavior matches a request, Azion looks in its cache for a compressed version of the file. If the cache holds one, Azion delivers it to the browser. Otherwise, Azion compresses the file, delivers it, and adds the compressed version to the cache. The browser then decompresses the file.

Applications also offers Brotli compression, which typically achieves better compression ratios than gzip and delivers smaller files. To turn on Brotli for an application, contact Azion Support. For more information, refer to [Support](/en/documentation/support/).

---

## Prerequisites

- An application that a [workload](/en/documentation/platform/workloads/) delivers, with a rule that sends its requests to an origin. To create both, refer to [Applications quickstart](/en/documentation/platform/applications/quickstart/).
- Access to Azion Console. To sign in, refer to [Access Azion Console](/en/documentation/guides/platform/account-and-billing/how-to-access-azion-console/).

---

## Turn on gzip compression

The rule in this section compresses content with gzip when the browser of the user supports it. Its behavior requires no Product on the application, and it runs in either phase. The rule matches every request of the application, because every path starts with `/`.

To create the rule in Azion Console:

1. **Open the application**

   Access [Azion Console](https://console.azion.com/) > **Applications** > **your application**.

2. **Select the Rules Engine tab**

3. **Select + Rule**

4. **Name the rule**

   In the **General** section, enter a **Name** for the rule, such as `gzip-compression`.

5. **(Optional) Describe the rule**

   In **Description**, enter a short note about what the rule does.

6. **Select the phase**

   In the **Phase** section, select **Request Phase** or **Response Phase**. The phase of a rule cannot change after you create the rule.

7. **Set the criterion**

   In the **Criteria** section, select `${uri}` as the variable and `starts_with` as the operator.

8. **Enter the path**

   Enter `/` as the argument. To compress only part of the application, set other criteria instead.

9. **Add the gzip behavior**

   In the **Behaviors** section, select the behavior that turns on gzip compression. The API names it `enable_gzip`.

10. **Select Save**

The rule appears in the **Rules Engine** tab, under the phase you selected. When the browser supports gzip, the responses to the requests the rule matches arrive compressed. For the variables and operators other criteria can use, refer to [Criteria](/en/documentation/platform/applications/rules-engine/#criteria). For the behavior, refer to [Enable Gzip](/en/documentation/platform/applications/rules-engine/#enable-gzip).

---

## Confirm that responses are compressed

A response that Azion compressed with gzip carries the `Content-Encoding` header with the value `gzip`. Azion compresses the files whose MIME type is one of the supported MIME types on this page.

To confirm the compression in a browser:

1. Access a page of your application.
2. Inspect the page with the developer tools of your browser.
3. Select the request for a file of a supported MIME type, such as a CSS or JavaScript file.

The response headers of that request carry `Content-Encoding: gzip`.

---

## Supported MIME types

Azion applies gzip compression to the file types that this table lists. Azion identifies each file by its Multipurpose Internet Mail Extensions (MIME) type. A web server sends the MIME type of a file to the browser in the `Content-Type` header. The browser reads it to know what the document, file, or byte array is, and how to process it.

A MIME type is a type and a subtype joined by a slash. The type names the category of the data, such as `text` or `image`. The subtype names the exact format, such as `jpeg` or `png`. For example, when your browser finds an `<img>` HTML tag for a PNG image, it requests the image. The server answers with `Content-Type: image/png`.

A compressed file keeps the MIME type of the original file in its `Content-Type` header, because the browser decompresses the file once the request ends. The [Internet Assigned Numbers Authority (IANA)](https://www.iana.org/assignments/media-types/media-types.xhtml) is responsible for all official MIME types.

| MIME type                       | Extension                                 | Document type                        |
| ------------------------------- | ----------------------------------------- | ------------------------------------ |
| `application/eot`               | `.eot`                                    | MS Embedded OpenType fonts           |
| `application/font`              | Not listed                                | OpenType font                        |
| `application/font-sfnt`         | `.ttf`, `.otf`                            | SFNT format                          |
| `application/font-woff`         | `.woff`                                   | Web Open Font Format (WOFF)          |
| `application/font-woff2`        | `.woff2`                                  | Web Open Font Format 2 (WOFF2)       |
| `application/javascript`        | `.js`                                     | JavaScript                           |
| `application/json`              | `.json`                                   | JSON format                          |
| `application/ld+json`           | `.jsonld`                                 | JSON-LD format                       |
| `application/opentype`          | `.otf`, `.otc`, `.ttf`, `.ttc`            | OpenType                             |
| `application/otf`               | `.otf`                                    | OpenType                             |
| `application/truetype`          | `.ttf`, `.tte`                            | TrueType                             |
| `application/ttf`               | `.ttf`                                    | TrueType                             |
| `application/vnd.ms-fontobject` | `.eot`                                    | MS Embedded OpenType fonts           |
| `application/x-font-opentype`   | `.otf`                                    | OpenType                             |
| `application/x-font-truetype`   | `.ttf`                                    | TrueType                             |
| `application/x-font-ttf`        | `.ttc`, `.ttf`                            | TrueType                             |
| `application/x-httpd-cgi`       | `.pl`, `.sh`, `.cgi`                      | CGI scripts/programs                 |
| `application/x-javascript`      | `.js`                                     | JavaScript                           |
| `application/x-mpegurl`         | `.M3U8`                                   | iPhone Index                         |
| `application/x-opentype`        | `.ttc`                                    | OpenType font                        |
| `application/x-otf`             | `.otf`                                    | OpenType font                        |
| `application/x-perl`            | `.plx`, `.pl`, `.pm`, `.xs`, `.t`, `.pod` | Perl script                          |
| `application/x-ttf`             | `.ttf`                                    | TrueType                             |
| `application/xhtml+xml`         | `.xhtml`                                  | XHTML                                |
| `application/xml+rss`           | `.rss`, `.xml`                            | RSS, Atom and XML                    |
| `font/eot`                      | `.eot`                                    | Embedded Open Type                   |
| `font/opentype`                 | `.otf`, `.otc`, `.ttf`, `.ttc`            | OpenType font                        |
| `font/otf`                      | `.otf`                                    | OpenType font                        |
| `font/ttf`                      | `.ttf`                                    | TrueType font                        |
| `image/svg+xml`                 | `.svg`                                    | Scalable Vector Graphics (SVG)       |
| `image/x-icon`                  | `.ico`                                    | ICO                                  |
| `text/css`                      | `.css`                                    | Cascading Style Sheets (CSS)         |
| `text/csv`                      | `.csv`                                    | Comma-separated values (CSV)         |
| `text/html`                     | `.htm`, `.html`                           | HyperText Markup Language (HTML)     |
| `text/javascript`               | `.js`                                     | JavaScript                           |
| `text/js`                       | `.js`                                     | JavaScript                           |
| `text/plain`                    | `.txt`                                    | Text (generally ASCII or ISO 8859-n) |
| `text/richtext`                 | `.rtf`                                    | Rich Text Format                     |
| `text/tab-separated-values`     | `.tsv`, `.tab`                            | Tab-separated values                 |
| `text/x-component`              | `.htc`                                    | HTML Components                      |
| `text/x-java-source`            | `.jav`                                    | Java Source                          |
| `text/x-markdown`               | `.md`                                     | Markdown                             |
| `text/x-script`                 | `.hlb`                                    | HP OpenVMS                           |
| `text/xml`, `application/xml`   | `.xml`                                    | XML                                  |

---

## Next steps

- [Rules Engine for Applications](/en/documentation/platform/applications/rules-engine.md#enable-gzip): The gzip behavior, the phases it runs in, and every other behavior a rule can carry.
- [Configure cache policies for an application](/en/documentation/guides/application-performance/cache-and-purge/cache-settings.md): Apply a cache setting that sets how long Azion keeps the files it delivers.
- [Check the cache status of a response](/en/documentation/guides/application-performance/cache-and-purge/check-page-cache-time.md): Find out whether a response came from Azion's cache.
- [Debug rules created with Rules Engine](/en/documentation/guides/application-development/getting-started/debug-rules.md): Find out whether a rule ran on a request, through the GraphQL API, Data Stream, or Real-Time Events.
