Dynamic compression automatically compresses responses served by Cloud CDN. The size of the data sent over the network is reduced by 60% to 85% in typical cases.
The size reduction reduces the time it takes to download content. For important assets like stylesheets (CSS), scripts (JavaScript), and video manifests (HLS/DASH), this can reduce page load and video start times.
You can learn more about the benefits of compressing responses in the Web Fundamentals guide.
You can enable compression on a backend service or a backend bucket.
Example use cases
Dynamic compression directly reduces the size of data sent from the Cloud CDN edge to the client. This can directly do the following:
- Reduce the size of CSS and JavaScript, helping web pages render faster and reducing the time to First Contentful Paint, an important web performance metric.
Have a large, positive impact when caching REST API responses, such as JSON payloads. These payloads compress well due to the repeated keys, whitespace, and braces. Caching public APIs for 5-10 seconds is a popular approach to reducing origin load while maintaining the freshness of data.
Even without caching, compressing these responses can reduce the total bytes sent by up to 90%.
Improve playback start time for video delivery and join latency for live streaming. Large live playlists (manifests) have a significant amount of repeated data, including the host + path prefix of each segment, as well as the HLS or DASH playlist metadata. The faster the playlist loads or playlist updates can be downloaded, the less time a client is waiting to parse and start downloading the referenced video segments. HLS and DASH playlists often see a total size reduction of more than 90%.
Before you begin
Make sure that you have the following:
- A Cloud CDN-enabled backend configured. If you don't have Cloud CDN configured, you can follow one of the setup guides.
- Your backend has compressible content ready to serve, such as web assets or video manifests between 1 KiB and 10 MiB (inclusive).
- Clients don't rely on fetching partial content with range requests or with strong ETags. These are incompatible with dynamic compression.
- Clients can handle responses without
Content-Lengthheaders. For example, cache misses that Cloud CDN compresses don't haveContent-Lengthheaders. - The IAM
Compute Load Balancer Admin role
(
roles/compute.loadBalancerAdmin), which is required to make changes to your backend configuration.
Enable compression on a backend service or backend bucket
To enable compression, follow these steps.
Console
Add a new origin
To add and set up a new origin, follow the instructions in Setup overview for the appropriate type of backend. When creating your origin, use the Advanced options section to configure dynamic compression by selecting Automatic in the Compression mode list.
Edit an existing origin
To edit an existing Cloud CDN origin:
In the Google Cloud console, go to the Cloud CDN Origins page.
Click the origin name that you want to edit, and then click Edit.
In the Origin basics section, click Next.
In the Host and path rules section, click Next.
In the Cache performance section, navigate to Advanced options.
In the Compression mode list, select Automatic.
To apply your changes, click Done.
gcloud
For backend services, use the gcloud compute backend-services
create command or
gcloud compute backend-services
update command
with the --compression-mode flag.
For backend buckets, use the gcloud compute backend-buckets create command
or the gcloud compute backend-buckets update command
with the --compression-mode flag.
For a new backend service, use the create command:
gcloud compute backend-services create BACKEND_SERVICE_NAME \
--compression-mode=AUTOMATIC
For an existing backend service, use the update command:
gcloud compute backend-services update BACKEND_SERVICE_NAME \
--compression-mode=AUTOMATIC
For a new backend bucket, use the create command:
gcloud compute backend-buckets create BACKEND_BUCKET_NAME
--compression-mode=AUTOMATIC
For an existing backend bucket, use the update command:
gcloud compute backend-buckets update BACKEND_BUCKET_NAME
--compression-mode=AUTOMATIC
The compression-mode can be one of the following:
AUTOMATIC: Automatically uses the best compression based on theAccept-Encodingheader sent by the client. In most cases, this results in Brotli compression being favored.DISABLED(default): Disables compression.