Enabling automatic gzipping
Last updated August 11, 2020
Fastly's gzip feature dynamically fetches content from origin, compresses it, and then caches it. There are two ways to enable gzip:
- Enable the default gzip policy to compress content in files with the following extensions:
css js html eot ico otf ttf json svg
. - Set up an advanced gzip policy to customize the content and conditions for compression.
IMPORTANT: Fastly provides support for Brotli compression as part of a limited availability release. To enable this feature for your account, contact support@fastly.com. For more information, see our product and feature lifecycle descriptions.
Enabling gzip
To dynamically gzip cacheable content based on file extension or content-type, follow the steps below to enable the default gzip policy:
- Log in to the Fastly web interface and click the Configure link.
- From the service menu, select the appropriate service.
- Click the Edit configuration button and then select Clone active. The Domains page appears.
- Click the Content link. The Content page appears.
- Click the Default gzip policy switch to enable gzip.
- Click the Activate button to deploy your configuration changes.
Setting up an advanced gzip policy
To customize the content that’s compressed and the conditions under which this compression occurs, follow the steps below:
- Log in to the Fastly web interface and click the Configure link.
- From the service menu, select the appropriate service.
- Click the Edit configuration button and then select Clone active. The Domains page appears.
- Click the Content link. The Content page appears.
- Click the Set up advanced gzip button. The Create a gzip page appears.
-
Click the Override these defaults link. Additional gzip fields appear.
- Fill out the Create a gzip fields as follows:
- In the Name field, type an arbitrary name for your new gzip rule.
- In the Extensions field, type the file extension for each file type to be dynamically gzipped, separated by spaces. Only type the three- or four-letter string representing the file extension.
- In the Content Types field, type the content-type for each type of content you wish to have dynamically gzipped, separated by spaces. Do not use regular expressions.
- Click the Create button. The new gzip policy appears.
- Click the Activate button to deploy your configuration changes.
Automatic normalization
Because gzip is one of the most common reasons to vary output based on a request header, Fastly will normalize the value of Accept-Encoding
on incoming requests. The modified header will be set to a single encoding type, or none, and will reflect the best compression scheme supported by the browser. This includes removing Accept-Encoding values in requests from browsers that advertise support for gzip but whose implementation is broken, such as IE6.
Specifically, we run the following steps on inbound requests:
- If the
User-Agent
matches a pattern for browsers that have problems with compressed responses, remove theAccept-Encoding
header - Else if the
Accept-Encoding
header includes the string "gzip", set the entire value to the string "gzip" - Else if the
Accept-Encoding
header includes the string "deflate", set the entire value to the string "deflate" - Else remove the
Accept-Encoding
header
Where this normalization process has changed the header value, the original value is made available in the custom header Fastly-Orig-Accept-Encoding
.
If a user agent advertises support for Brotli, currently we will normalize this to gzip because we do not support Brotli encoding at the edge. However, if you are doing Brotli encoding at your origin server, you may want to modify our normalization algorithm.
Back to Top