All Products
Search
Document Center

CDN:Use Alibaba Cloud CDN to accelerate the delivery of images in OSS

Last Updated:Dec 15, 2025

You can use Alibaba Cloud CDN to accelerate the delivery of images in Object Storage Service (OSS). This speeds up access and reduces data transmission costs. If you want to analyze user access behavior, you can use features that are provided by Alibaba Cloud CDN, such as monitoring, usage analytics, and operations reports, to help you modify operation policies based on your business requirements.

Scenario

使用CDN来加速OSS上存储的文件资源分发

When you operate an e-commerce website, you need to upload and download a large number of product images, and ensure seamless access for all users to the website. In this case, you can store images in OSS and use Alibaba Cloud CDN to accelerate image delivery. This speeds up access, improves server stability, and reduces traffic costs. Alibaba Cloud CDN caches images from OSS to the points of presence (POPs) that are nearest to clients. When a client accesses an image, the image is retrieved from the nearest POP instead of the OSS bucket. This reduces latency and improves resource access efficiency.

Benefits

Cost saving

The unit price of Alibaba Cloud CDN traffic is lower than the unit price of outbound traffic over the Internet from OSS. For example, you use Alibaba Cloud CDN to accelerate the delivery of images in OSS, the origin fetch fee is ignored, and the monthly traffic is 1 TB. In this case, if you purchase a CDN resource plan, the cost is reduced by approximately 78.6% from USD 70 to USD 15 compared to using OSS outbound traffic.

image

You may incur fees for CDN outbound traffic and for origin traffic from OSS to CDN. For more information, see Billing of OSS content acceleration.

User experience improvement

Alibaba Cloud CDN caches images from OSS to the POPs that are nearest to clients. Clients can retrieve images from the nearest POP. This reduces page loading time.

Alibaba Cloud CDN also provides features, such as image editing, to optimize image access performance. For example, you can enable the image compression feature on POPs. After an image is compressed, the size of the image is reduced, and access to the image is accelerated. If you enable the image compression feature and set the compression rate to 90% for an image whose size is 516 KB, the image is compressed without changing the resolution, size, or format, and its loading time is reduced by 50% from 50 ms to 25 ms. For more information, see Step 4: Optimize image access performance.

image

User access behavior analytics

Alibaba Cloud CDN provides features, such as monitoring, usage analytics, and operations reports, to analyze page views (PVs), unique visitors (UVs), and user distribution by region of your website, such as an e-commerce website. This helps you analyze traffic trends and sources, and modify operation policies based on your business requirements.

For example, you can use the Popular Referer Headers metric in operations reports to evaluate advertising effects. If the reports show that a large number of requests are redirected from specific advertising channels, the advertising channels work as expected. Otherwise, you can stop advertising in the channels.

image

Prerequisites

  • An Alibaba Cloud account is created, and real-name verification is completed for the account. For more information, visit the Sign up to Alibaba Cloud and Real-name Registration pages.

  • OSS is activated, an OSS bucket is created, and resources are uploaded to the bucket. For more information about how to activate OSS, see Activate OSS.

Configure Alibaba Cloud CDN to accelerate the delivery of images in OSS

Step 1: Activate Alibaba Cloud CDN and add a domain name to accelerate

  1. Log on to the Alibaba Cloud CDN console.

  2. In the left-side navigation pane, click Domain Names. On the Domain Names page, click Add Domain Name and configure the following parameters:

    • Domain Name to Accelerate: the domain name that is used by users to access your website. In this example, enter image.example.com.

    • Business Type: We recommend that you select Image and Small File.

    • Region: the region in which you want to accelerate the delivery of images in OSS, such as Chinese Mainland Only.

    Note

    The first time you add a domain name to Alibaba Cloud CDN, the system verifies the ownership of the domain name before you can add the domain name. Follow the on-screen instructions to complete the verification. For more information, see Verify the ownership of a domain name.

  3. Click Add Origin Server and configure the parameters. Set the Origin Info parameter to OSS Domain and select the OSS bucket that you want to accelerate from the Domain Name drop-down list. Retain the default values for other parameters and click OK.

  4. After you add an origin server, read and select the compliance commitment, click Next, and then wait for manual review.

    Note

    If your accelerated domain name does not require manual review, you can proceed to the next step. You can configure the cache expiration, bandwidth cap, and HTML optimization features in the Recommended Features step based on your business requirements. The features improve the cache hit ratio, security, and access performance of Alibaba Cloud CDN.

  5. When the Status of the domain name is Enabled, obtain the CNAME of the accelerated domain name. In this example, the CNAME is image.example.com.w.kunlunsl.com. image

Step 2: Add a CNAME record

After you add a domain name to Alibaba Cloud CDN, the system assigns a CNAME to the domain name. Before you can redirect requests to POPs, you must add a CNAME record in the system of your DNS service provider to map the domain name to the CNAME.

In the following example, Alibaba Cloud DNS is used to show how to add a CNAME record. For more information, see Configure a CNAME record.

  1. Log on to the Alibaba Cloud DNS console with the Alibaba Cloud account to which the accelerated domain name belongs.

  2. In the left-side navigation pane, click Public Zone. Find the domain name for which you want to add a CNAME and click DNS Settings in the Actions column.

  3. Click Add DNS Record and add a CNAME record.

    • Record Type: Select CNAME.

    • Hostname: Enter image.

    • Record Value: Enter the CNAME assigned by Alibaba Cloud CDN to your accelerated domain name, such as image.example.com.w.kunlunsl.com.

    • Retain the default values for other parameters.

  4. Click OK.

Step 3: Configure cache rules

POPs determine whether to cache the image that is requested by the client based on the cache rule that you configure, such as the cache time-to-live (TTL). After POPs cache the image, when other users request the image, POPs can return the image to the users. This reduces latency and improves resource access efficiency. If the image requested by users does not exist on POPs or has expired, POPs initiate an origin request to OSS to retrieve the most recent image. You can create a cache rule for static resources based on file directories or file name extensions.

Note

If you have configured the TTL in the Recommended Features step when you add a domain name to Alibaba Cloud CDN, the TTL of resources in the directory is one month. You can determine whether to change the TTL based on your business requirements.

  1. Log on to the CDN console.

  2. In the left-side navigation pane, click Domain Names.

  3. On the Domain Names page, find the target domain name and click Manage in the Actions column.

  4. In the left-side navigation tree of the domain name, click Cache.

  5. On the Cache Expiration tab, click Create Rule.

  6. In the Create Expiration Rule dialog box, configure the following parameters:

    • Type: Select File Extension.

    • File Extension: Enter the extensions of files that you want to cache. In this example, enter jpg.

    • Expire In: Specify a value of one month or longer for static files that are infrequently updated, such as images and application packages. This can reduce origin traffic.

      Note

      If a POP retrieves a static file from an origin server, the POP processes the file based on the priorities of the cache rules. For more information, see Default Alibaba Cloud CDN cache rules and priorities.

    • Weight: Enter 99.

  7. Click OK.

Step 4: Optimize image access performance

You can use the image editing and ignore parameters features provided by Alibaba Cloud CDN to accelerate response when users request images.

Image editing

You can enable the image compression feature on POPs. After an image is compressed, the size of the image is reduced and access to the image is accelerated. You do not need to process the image on the origin server. This reduces the loads on the origin server and origin traffic.

Note

The automatic compression feature may change the resolution of images. Specify a proper compression rate based on your business requirements.

Example

  1. Upload an image to the OSS bucket and request the image without enabling the image editing feature in Alibaba Cloud CDN. The image is 517 KB in size and is loaded in 50 ms.image

  2. Enable the image editing feature.

    • Supported Image Formats: JPG.

    • Automatic Compression: 90%.

    • Retain the default values for other parameters.

    image

  3. Re-access this image, the image is reduced to 147 KB in size and is loaded in 25 ms. The loading time is reduced by 50%.image

    Note

    After you enable the image editing feature, the POP processes the image the first time a user requests the image. The image size decreases, but the loading time increases. Then, the processed image is cached on POPs, resulting in shorter loading time for subsequent requests.

Ignore parameters

If request URLs to the same image contain different parameters, the requests for the image cannot hit the same cache file. Each request is redirected to the origin server to retrieve the image. After you enable the ignore parameters feature, POPs remove the parameters that follow the question mark (?) in request URLs, such as user identity and access source, when processing user requests and return the image that corresponds to the original URL. This reduces the trips to the origin and origin traffic, and accelerates image delivery.

Note

If you have configured the ignore parameters feature in the Recommended Features step when you add the accelerated domain name, skip this step. For more information, see Ignore parameters.

  1. Log on to the CDN console.

  2. In the left navigation pane, click Domain Names.

  3. On the Domain Names page, find the target domain name and click Manage in the Actions column.

  4. In the domain's navigation pane, click Optimization.

  5. In the Ignore Parameters section, click Modify. Set the Filter Mode parameter to Retain Specified Parameters and the Ignore Parameters parameter to Yes, retain the default values for other parameters, and then click OK.

Step 5: (Optional) Analyze user access behavior by using the operations reports and monitoring features

Create an operations report

You can create a custom operations report and a tracking task to analyze access to your e-commerce website, such as PVs, UVs, user regions, and popular URLs. For example, you can use the Popular Referer Headers metric in operations reports to evaluate advertising effects. If the reports show that a large number of requests are redirected from specific advertising channels, the advertising channels work as expected. Otherwise, you can stop advertising in the channels.

Note

You need to create a custom operations report to generate statistical data for analysis.

image

Alibaba Cloud CDN monitoring and usage analytics

The resource monitoring feature allows you to view statistics such as access traffic and bandwidth, origin traffic and bandwidth, the number of requests, and the hit ratio. You can also export reports.

On the Data Transfer/Bandwidth of Requests tab, you can compare data transfer between two different time ranges. This helps you monitor the advertising and operations of your website.

监控查询

Related operations

Purge the image cache

After you update an image in an OSS bucket, users may still retrieve the original image because the image is cached on POPs. In this case, you need to use the purge feature to remove the cached image on POPs and force the POPs to retrieve the updated image from the OSS bucket.

  1. Log on to the CDN console.

  2. In the left-side navigation pane, click Purge and Prefetch.

  3. On the Refresh/Prefetch tab, configure the following parameters:

    • Operation: Select Purge.

    • Operation Method: Select URL.

    • URL: Enter the URL of the image that you want to purge.

Example

  1. Upload the pic_02.jpg image to the OSS bucket and cache the image on POPs for 30 days, which is 2,592,000 seconds. You can view the following information in a browser.image

  2. Update the image in the OSS bucket and access the image. The image that is cached on POPs is obtained.

  3. Purge the cache in the Alibaba Cloud CDN console.

  4. Re-access the image in the browser. The updated image is obtained.

    image

    The value of the last-modified header is changed and the image that you access is updated.