How to optimize image processing at the edge
Through the Image Processor module, you can adjust image sizes, add filters and watermarks, or convert formats to suit for more efficient content delivery, bandwidth saving, and reduce object storage costs. These changes can be applied directly in the URL of your image by appending ims
queries to the image’s URL.
- Access Azion Console > Edge Application.
- Click the edge application you want to configure.
- Activate the Application Accelerator and Image Processor modules.
- Click the Save button.
- Navigate to the Cache Settings tab.
- Click the + Cache Setting button.
- In the Cache Expiration Policies section, configure the expiration policy for your images.
- For images, you may add larger time-to-live (TTL) values, such as
1296000
seconds (15 days).
- In the Advanced Cache Key section, choose one of the following options:
- Content varies by some Query String fields (Allowlist): if you want to list all the fields in the Query String that will identify your images. Image Processor uses the ims field, so this has to be included in the list as one of the required fields for your image manager application.
- Content varies by Query String, except for some fields (Blocklist): if you only want to list those fields in the Query String that should be ignored to identify the objects in your cache. In this case, it guarantees that the ims field will be removed from the list.
- Content varies by all Query String fields: if you don’t know or aren’t sure about which fields to list in the Query String because you aren’t responsible for all the content in the cache or don’t have Application Accelerator activated.
- Click the Save button.
Now you need to indicate what will trigger the activation of the Image Processor module. You can create a rule that identifies image formats as follows:
- Still on the Edge Application page, navigate to the Rules Engine tab.
- Click the + Rule button.
- Name your rule.
- Select Request Phase.
- In the Criteria section, select the variable
${request_uri}
. - Select the comparsion operator matches
- As an argument, add
\.(jpg|jpeg|gif|bmp|png)
. - Click + Or to add another criterium.
- In the new field, select the variable
${uri}
. - Select the comparsion operator matches
- As an argument, add
\.(jpg|jpeg|gif|bmp|png)$
- In the Behavior section, select Set Cache Policy and select the cache setting you created.
- Click the + Add Behavior button.
- Add the Optimize Images behavior.
- Click the Save button to save your rule.
To confirm whether your image is being optimized, inspect the page using your browser and find the corresponding path in the image. In the URL’s query string, the ims=VALUExVALUE
field corresponds to the resolution loaded on the page. To see the original file, you only need to remove the query string added in the URL.
- Access Real-Time Manager (RTM).
- On the upper-left corner of the page, open the Products menu, represented by three horizontal lines, and select Edge Application.
- Click the edge application you want to configure.
- Activate the Application Accelerator and Image Processor modules.
- Navigate to the Cache Settings tab.
- Click the Add Cache Settings button.
- In the Expiration Settings section, configure the expiration policy for your images.
- For images, you may add larger time-to-live (TTL) values, such as
1296000
seconds (15 days).
- In the Advanced Cache Key section, choose one of the following options:
- Content varies by some Query String fields (Whitelist): if you want to list all the fields in the Query String that will identify your images. Image Processor uses the ims field, so this has to be included in the list as one of the required fields for your image manager application.
- Content varies by Query String, except for some fields (Blacklist): if you only want to list those fields in the Query String that should be ignored to identify the objects in your cache. In this case, it guarantees that the ims field will be removed from the list.
- Content varies by all Query String fields: if you don’t know or aren’t sure about which fields to list in the Query String because you aren’t responsible for all the content in the cache or don’t have Application Accelerator activated.
- Click the Save button.
Now you need to indicate what will trigger the activation of the Image Processor module. You can create a rule that identifies image formats as follows:
- Still on the Edge Application* page, navigate to the Rules Engine tab.
- Click the Add Rule button and select Request Phase.
- Name your rule.
- In the Criteria section, select the variable
${request_uri}
. - Select the comparsion operator matches
- As an argument, add
\.(jpg|jpeg|gif|bmp|png)
. - Click Or to add another criterium.
- In the new field, select the variable
${uri}
. - Select the comparsion operator matches
- As an argument, add
\.(jpg|jpeg|gif|bmp|png)$
- In the Behavior section, select Set Cache Policy and select the cache setting you created.
- Click the + button.
- Add the Optimize Images behavior.
- Click the Save button to save your rule.
To confirm whether your image is being optimized, inspect the page using your browser and find the corresponding path in the image. In the URL’s query string, the ims=VALUExVALUE
field corresponds to the resolution loaded on the page. To see the original file, you only need to remove the query string added in the URL.
- Run the following
PATCH
request in your terminal, replacing[TOKEN VALUE]
with your personal token and the<edge_application_id>
variable with your edge application ID to activate the Application Accelerator and Image Processor modules:
- You’ll receive a response with the updated value.
- Run the following
POST
request in your terminal, replacing[TOKEN VALUE]
with your personal token and the<edge_application_id>
variable with theid
of your edge application:
- You’ll receive a response similar to this:
- Copy the cache setting ID received in the response.
- Run the following
POST
request to create a rule in the Request Phase, replacing the edge application ID value and the cache setting ID you received in the previous response:
- You’ll receive the following response:
To confirm whether your image is being optimized, inspect the page using your browser and find the corresponding path in the image. In the URL’s query string, the ims=VALUExVALUE
field corresponds to the resolution loaded on the page. To see the original file, you only need to remove the query string added in the URL.