Compress application responses with gzip
Create a Rules Engine rule that compresses the responses of an application with gzip, and look up the MIME types that Azion compresses.
You can compress the responses of an application with gzip from Azion Console, with a rule in Rules Engine for Applications.
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.
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.
Prerequisites
- An application that a workload delivers, with a rule that sends its requests to an origin. To create both, refer to Applications quickstart.
- Access to Azion Console. To sign in, refer 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:
Access Azion Console > Applications > your application.
In the General section, enter a Name for the rule, such as gzip-compression.
In Description, enter a short note about what the rule does.
In the Phase section, select Request Phase or Response Phase. The phase of a rule cannot change after you create the rule.
In the Criteria section, select ${uri} as the variable and starts_with as the operator.
Enter / as the argument. To compress only part of the application, set other criteria instead.
In the Behaviors section, select the behavior that turns on gzip compression. The API names it enable_gzip.
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. For the behavior, refer to 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:
- Access a page of your application.
- Inspect the page with the developer tools of your browser.
- 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) 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 |