Enabling Gzip Encoding
In the Delivery section of Apple's HLS Authoring specification, 10.1 states that "the server MUST deliver playlists using gzip content-encoding."
This article will show you how to enable gzip encoding for the Apache2 and Nginx web servers. The instructions are specifically for the Ubuntu Linux distribution so the location of the files you will need to edit may vary depending on what distribution you are using.
Apache2
To enable gzip compression for HLS playlists, add the following lines to the main Apache configuration file (e.g. /etc/apache2/apache2.conf
):
<IfModule mod_deflate.c> AddOutputFilterByType DEFLATE application/vnd.apple.mpegurl # Set compression level (1-9, 9 being maximum compression) DeflateCompressionLevel 6 </IfModule>
This tells Apache to compress any files with the "application/vnd.apple.mpegurl
" MIME type, which just happens to correspond to MIME type of an HLS playlist.
Reload (or restart) Apache to enable the changes.
To test the configuration and confirm gzip compression is working, either use a browser developer tool (e.g. Chrome Dev tools) and check the response headers, or use curl
:
$ curl -H "Accept-Encoding: gzip" -I http://yourdomain.com/playlist.m3u8
Look for the "Content-Encoding: gzip
" header in the server’s response. If it's present, gzip compression is enabled.
Nginx
To enable compression in Nginx, set the gzip
directive to on. By default, Nginx will only compress HTML files (text/html
). To compress HLS playlists, you will also need to set the gzip_types
directive and set it to the MIME type of an HLS playlist.
Here's an example (default) server configuration that enables gzip compression for HLS playlists:
server { listen 80; listen [::]:80; server_name localhost; gzip on; gzip_types application/vnd.apple.mpegurl; gzip_vary on; location / { root /usr/share/nginx/html; index index.html index.htm; } }
To check that gzip compression is enabled, run the following command, replacing the URL with the URL of your playlist:
$ curl -H "Accept-Encoding: gzip" -I http://yourdomain.com/playlist.m3u8
You should see a response like this:
HTTP/1.1 200 OK Server: nginx/1.26.2 Date: Wed, 26 Mar 2025 18:22:32 GMT Content-Type: application/vnd.apple.mpegurl Connection: keep-alive Vary: Accept-Encoding Content-Encoding: gzip
Nginx also has the gzip_min_length
directive, which allows you to specify the minimum length (in bytes) of the file to be gzipped; the default is 20 bytes meaning that if your playlists are less than this, they won't be compressed. Why would you want to set this? Well, although the guidelines state that playlists must be compressed, it really depends on the size of your playlist. Nginx compresses the files at runtime so it can add considerable processing overhead, which could negatively affect performance. Something to think about.
The gzip directives that configure compression can be included either in the http
context or in a server
or location
block. The example config above is for a specific site. If you want to apply the configuration globally then you would add the gzip directives to the http
context in the file /etc/nginx/nginx.conf
.
For comments, please send me an email