How to enable gzip compression for Edge Application
Gzip is the standard method for lossless file compression for web applications. By using the Deflate algorithm to reduce the size of files before they’re sent to browsers, gzip compression ensures faster page rendering and downloads for your users.
When you enable gzip compression for Azion Edge Application, the following events take place during a request for content from your application:
- At the edge node, Azion verifies the cache for a compressed version of the file.
- If the file’s already compressed, it’s delivered to the browser. If it isn’t, Azion compresses the file, returns it to the browser, and adds it to the cache.
- The browser interprets and decompresses the file.
Enabling gzip compression through Rules Engine
You can enable gzip compression for any edge application using the Rules Engine for Edge Application.
To enable gzip compression for your application, follow these steps:
- Access Azion Console > Edge Application.
- Click on the application you want to configure.
- In the Rules Engine tab, click the + Rule button.
- Give your rule a name and, if necessary, a description.
- Select either Response Phase or Request Phase.
- In the Criteria section, define the desired criteria for activation of the behavior.
- To apply gzip compression for your entire application, you can set a default criteria as follows: If
${uri}
starts with/
- To apply gzip compression for your entire application, you can set a default criteria as follows: If
- In the Behavior section, select the Enable gzip behavior.
- Click the Save button.
- Access Real-Time Manager (RTM).
- Select Products menu > Edge Application.
- Click on the application you want to configure.
- In the Rules Engine tab, click the Add Rule button and select either Response Phase or Request Phase.
- Give your rule a name and, if necessary, a description.
- In the Criteria section, define the desired criteria for activation of the behavior.
- To apply gzip compression for your entire application, you can set a default criteria as follows: If
${uri}
starts with/
- To apply gzip compression for your entire application, you can set a default criteria as follows: If
- In the Behavior section, select the Enable gzip behavior.
- Click the Save button.
To verify whether gzip compression has been applied, access your application and inspect the page. The Content-Encoding
request header should contain the value gzip
.
Support for gzip compression
Azion servers support gzip compression for some file extensions, which are identified via their MIME (Multipurpose Internet Mail Extensions) type.
About MIME types
Whenever a page loads within a web browser, a web server sends information regarding the contents and data of the page to the browser. Such details are stored in request headers and they are passed to the browser so that it can load and interpret the page.
The Content-Type
header is responsible for processing page contents through the MIME type. MIME types inform the types of documents, files, or byte arrays within the web application, as well as how they should be processed.
MIME types consist of a type and subtype combined by a /
symbol in between each other. The type represents the category of that data file; for instance, text
or image
. The subtype stands for the exact data type represented by the MIME type. For instance, the MIME type image
could carry a subtype jpeg
or png
.
Therefore, when your browser runs into an <img>
HTML tag, it sends out a request to the server. If this image is a .png, the server will return the header and MIME type: Content-Type: image/png
.
The entity responsible for all official MIME types is the Internet Assigned Numbers Authority (IANA).
Files that have undergone gzip compression should retain their original MIME type on the request header, since the browser is responsible for decompressing the file upon the end of the request.
List of supported MIME types for gzip compression
MIME Type | Extension | Document type |
---|---|---|
application/eot | .eot | MS Embedded OpenType fonts |
application/font | 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 |