This page helps you to get started with Cloud CDN image optimization, explaining how to configure image optimization and list of supported operations with examples.
Prerequisites
For Cloud CDN image optimization to work, make sure that the following prerequisites are met:
Cloud CDN cache policy must be enabled on the URL route or the associated backend service or bucket, and the image optimization feature must be active on that URL map route.
Image optimization is supported for Global External Application Load Balancers only. classic Application Load Balancer is not supported.
Supported HTTP methods:
GET: performs image transformations and edge caching forGETrequests.HEAD: if theimopquery parameter is present, returns cached headers (includingContent-Length) on cache hits; on cache misses, validates headers, setsContent-Typeto the target output format, and strips originContent-Lengthwithout invoking edge transformation or billing.OPTIONS: if theimopquery parameter is present, returns anHTTP 204 No Contentresponse withAllow: OPTIONS, GET, HEAD.Unsupported methods (
POST,PUT,DELETE,PATCH): If theimopquery parameter is present, Cloud CDN rejects requests at the edge and returns anHTTP 405 Method Not Allowederror.
Origin request behavior on cache misses: Cloud CDN sets
Accept-Encoding: identityand removes clientRangeheaders when fetching pristine images from the origin. This helps ensure complete payloads without HTTP compression, such asgziporbrotli.The client request should include an
Acceptheader indicating it can receive image content, such asimage/webp,image/avif,image/*, or*/*. If the header is absent,*/*is assumed by default.The origin server must respond with an
HTTP 200status code and a supported imageContent-Typeheader.The
imopquery parameter must be included in the URL and contain one or more valid transformation operations.
Operation
If the Content-Type header is a supported image format, the image is
optimized, cached, and served to the user. Requests without ?imop= bypass
image optimization and pass through unmodified.
However, if ?imop= is present but the content type is unsupported, an
HTTP 415 Unsupported Media Type error is returned instead of serving the raw
file unmodified (GET requests are still billed as transformations).
For unsupported content-encoding, if the origin ignores
Accept-Encoding: identity and sends any Content-Encoding header (for example,
gzip, br, deflate, or identity), Cloud CDN
aborts the request and returns HTTP 415 Unsupported Media Type.
Configure image optimization
Image optimization requires an active caching enabled. Ensure that you configure at least one of the following:
Backend-based caching: make sure the backend has Enable Cloud CDN checked.
URL map-level caching: ensure that a cache policy is configured at the URL map level for the specific path where you plan to enable image optimization.
gcloud
You can declare your URL map configuration in a YAML file and import it,
as image optimization policies are defined inside the routeAction object.
Export your existing URL map configuration to a local YAML file:
gcloud compute url-maps export YOUR_URL_MAP_NAME \ --global \ --destination=my-url-map.yaml
Edit the
my-url-map.yamlfile in a text editor and add theimageOptimizationPolicyfield to the selectedrouteActionordefaultRouteActionsection:name: image-matcher routeRules: - description: ImageOptimizationService matchRules: - prefixMatch: /images/ priority: 1 routeAction: imageOptimizationPolicy: queryParameterInterpretation: ENABLEDImport the updated URL map:
gcloud compute url-maps import YOUR_URL_MAP_NAME \ --global \ --source=my-url-map.yaml
Alternatively, to edit the file interactively in your default text editor, use the
gcloud compute url-maps editcommand:gcloud compute url-maps edit YOUR_URL_MAP_NAME --global
Terraform
Configure image optimization within your google_compute_url_map resource:
resource "google_compute_url_map" "urlmap" {
name = "image-url-map"
default_service = google_compute_backend_bucket.static.id
host_rule {
hosts = ["images.example.com"]
path_matcher = "imagematcher"
}
path_matcher {
name = "imagematcher"
default_service = google_compute_backend_bucket.static.id
path_rule {
paths = ["/images/*"]
service = google_compute_backend_bucket.static.id
route_action {
image_optimization_policy {
query_parameter_interpretation = "ENABLED"
}
}
}
}
}
GKE Gateway API
Configure image optimization on GKE Gateway using a GCPHTTPFilter:
Create a
GCPHTTPFiltermanifest (gcp-img-opt-filter.yaml):apiVersion: networking.gke.io/v1 kind: GCPHTTPFilter metadata: name: img-opt-filter spec: imageOptimizationPolicy: queryParameterInterpretation: ENABLEDAttach the filter to your
HTTPRouteusingextensionRef:apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: images-route spec: parentRefs: - kind: Gateway name: external-http hostnames: - "images.example.com" rules: - matches: - path: value: /images/ filters: - type: ExtensionRef extensionRef: group: networking.gke.io kind: GCPHTTPFilter name: img-opt-filter backendRefs: - name: images-backend port: 8080
Console
- In the Google Cloud console, go to the Load Balancing page.
- Click the name of your global external Application Load Balancer.
- Click Edit .
- Navigate to the Backend configuration tab.
- Configure caching: Image optimization requires active
caching to save successfully. Choose and configure one of the following,
for image optimization to work.
- Backend-based: Ensure Enable Cloud CDN is selected in your Backend Service configurations.
- URL map level:
- Navigate to Routing rules and select Advanced host and path rules.
- Define a cache policy at URL map level on the route where you are enabling image optimization.
Depending on your routing architecture, select one of the routing rules:
To use the default routing rule, do the following:
- In the Host and path rules section, under Action, select Route traffic to a single backend mode, and then select a backend from the list.
- Expand the Image optimization section (collapsed by default).
- Select the Enable Image optimization checkbox.
To use the custom routing rule, do the following:
- In the Host and path rules section, select Add host and path rule.
- In the Hosts field, enter * to match all hostnames.
- In the Path matcher section, use the YAML editor to define your configuration.
- Click Code guidance below the YAML editor for guidance on the code.
- Copy the snippet and paste it into the YAML editor.
- Update the placeholder values.
Review configurations
- Review your configurations.
- Click Done to close the sub-editor.
- Click Update to save your configurations.
Supported image formats
Cloud CDN image optimization supports a wide range of input formats from your origin server. While most formats can be used for processing and output, some formats are Input only and cannot be used as target output formats.
The following image formats are supported from your origin server:
| Format | Content-Type Header | Input/output | Usecase scenario |
|---|---|---|---|
| gif | image/gif |
Input and output | Standard animated/still format. Animated frames can be extracted
using the Freeze operation. |
| png | image/png |
Input and output | Lossless format, ideal for transparency, logos, and digital art. |
| webp | image/webp |
Input and output | Modern, web-optimized format with both lossy and lossless compression. |
| jpeg | image/jpeg |
Input and output | Standard photographic format. |
| brunsli | image/x-j |
Input and output (only when the origin image is already in this
format and Convert isn't specified) |
High-efficiency lossless JPEG repacking format. |
| tiff | image/tiff |
Input and output (only when the origin image is already in this
format and Convert isn't specified) |
High-quality tag-based raster format. |
| avif | image/avif |
Input and output | High-efficiency next-generation image format. |
| bmp | image/bmp |
Input only | Cannot be specified as an output format. Convert to WEBP or
JPEG using ?imop=Convert,format=webp. |
| ico | text/ico, image/ico, image/icon,
application/ico, image/x-icon, image/vnd.microsoft.icon |
Input only | Icon container format. Cannot be exported; convert to a supported output format for delivery. |
| jp2k | image/jp2 |
Input only | JPEG 2000 format. Must be explicitly converted using a
Convert operation. |
| heif | image/heif |
Input only | High Efficiency Image Format. Must be converted before edge delivery. |
Image transformation URL
To perform dynamic image transformations, add the imop query
parameter to your image URL. This parameter holds a transformation
string, which consists of one or more operations applied in sequence.
The transformation string uses the following format rules:
- Use a semicolon (
;) to separate each individual operation. - Use a comma (
,) to separate the internal parameters within each individual operation. - Only one operation of a given type can be included in a single query string.
The baseline syntax uses the following structure:
?imop=[OPERATION_1];[OPERATION_2];...[OPERATION_N]To perform multiple actions on an image simultaneously, append a chained parameter
string to the image URL. For example, to resize an image to 800 pixels wide,
set the compression quality to 85, and convert the format to WebP, append the
parameter string.
For example,
https://www.example.com/image.jpg?imop=Resize,width=800;Quality,level=85;Convert,format=webpPolicy structure
The image optimization policy acts as the core configuration wrapper containing every property relevant to the functionality of the image optimization feature.
Name |
Description |
Configuration |
|---|---|---|
|
Enum value that determines whether the query parameter for image optimization will be interpreted in the data plane. |
Required. If set to DISABLED, query parameters for transformation will be ignored by the policy, effectively disabling this feature. If set to ENABLED, this feature will be enabled. |
Policy dependencies and validation
The image optimization policy has a dependency on Cloud CDN caching. For this feature to work, a Cache Policy must be explicitly set on one of two locations:
The same URL map route where the Image optimization policy is being configured.
A backend service or backend bucket related to that exact route.
The image optimization policy is applied strictly in conjunction with the active, underlying Cache Policy.
Roles and permissions
To configure and manage the image optimization feature, you must have an Identity and Access Management (IAM) role that grants permission to modify load balancer URL maps.
Predefined roles
The following predefined roles provide the required permissions:
Compute Load Balancer Admin (
roles/compute.loadBalancerAdmin): provides full control over load balancing resources, including attaching image optimization policies to URL maps.Compute Network Admin (
roles/compute.networkAdmin): provides broader networking permissions, including full control over load balancing and URL maps.
Key permissions
If you use custom IAM roles, ensure that they include the following permissions:
compute.urlMaps.update: required to attach or modify an image optimization policy on a URL map.compute.urlMaps.getandcompute.urlMaps.list: required to view URL map configurations.compute.backendServices.update: required if configuring backend service-level caching.
Image optimization ordering rules
Operations listed in the imop query parameter are processed in a structured
execution pipeline:
FreezeandScale:If
Scaleis specified, it must be the first operation in the query string.If
Freezeis specified on an animated GIF, animated WebP, or animated AVIF/HEIF image, placeFreezeat the start of the query string (or immediately afterScaleifScaleis used) so frame extraction occurs before any subsequent geometric or visual filter transformations. PlacingFreezeafterBlur,Tone, orSharpenreturns anHTTP 500error.
Geometric and visual filter operations (
Crop,Rotate,Mirror,Resize,Blur,Tone, andSharpen):- These operations are executed sequentially from left to right in the exact order they appear in the query parameter string.
- Each operation acts on the visual output of the preceding operation.
Output encoding operations (
Convert,Compress,Quality,Metadata):- Format conversion, compression or numeric quality adjustment, and metadata preservation (including C2PA Content Credentials manifests) are applied during final output encoding.
Canvas:- If
Canvasis specified, it must be the last operation in the query string and is always applied last.
- If
All input assets undergo automatic normalization before Cloud CDN executes these transformations. Cloud CDN applies EXIF orientation markers and ICC color profiles directly to the image pixels before it strips any metadata. This process ensures that coordinate integrity remains accurate for subsequent structural actions.