Accelerate OSS image delivery with CDN
Use Alibaba Cloud CDN to accelerate the delivery of images from Object Storage Service (OSS). This solution improves access speed, reduces data transfer costs, and provides powerful analytics tools, such as monitoring queries and operations reports, to refine your business strategy.
Use cases
This best practice is based on the article Use CDN to accelerate the delivery of resources stored in OSS from the Alibaba Cloud community.

If you run an e-commerce website, you need to not only upload and download a large number of product images but also ensure a smooth browsing experience for all users. You can store your images in OSS to save costs. To improve access speed, enhance website stability, and reduce traffic costs, you can use CDN for acceleration. CDN caches images from your OSS bucket to Points of Presence (POPs) that are geographically closest to your users. When a user requests an image, the nearest POP serves it directly instead of from the origin server. This reduces latency and improves content delivery efficiency.
Benefits
Cost savings
The unit price of CDN traffic is lower than the price of outbound traffic from OSS. Using CDN to accelerate image delivery significantly reduces costs. For example, for 1 TB of monthly traffic, if you purchase a resource plan, you can save about 78.6% on traffic costs compared to using only OSS. This reduces your monthly bill from (CNY 505 to CNY 108), excluding fees for origin requests. For more information, see Accelerate access to static website resources.
Using OSS as a CDN origin server incurs fees for CDN data transfer and OSS-to-CDN origin fetch traffic. For more information, see Billing of OSS content acceleration.
Improved user experience
CDN caches images from your OSS bucket to POPs that are geographically closest to your users. Your users can always retrieve resources from the nearest POPs, which significantly reduces website load times.
CDN also provides features for performance optimization, such as image editing. For example, you can configure automatic compression for images on CDN POPs. Compressing images reduces their size and improves access speed. For a 517 kB image, after you enable automatic image compression at 90%, the image is compressed without changing its resolution, dimensions, or format. This can reduce the image loading time by 50% (from 50 ms to 25 ms). For more information, see Optimize image access performance.
Analyze user behavior
For an e-commerce website, you can use CDN features such as monitoring queries and operations reports to analyze website traffic, including page views (PV), unique visitors (UV), and user regional distribution. This helps you understand traffic trends and sources, enabling you to adjust your business strategies.
For example, to measure the effectiveness of your advertising campaigns, you can review the Popular Referer Headers report. High traffic from a specific channel indicates that the advertising campaign is performing well. You may consider pausing campaigns with low traffic.
On the Operations Reports page of the CDN console, select Popular Referer in the left-side menu. The table on the right displays the Traffic, Traffic Ratio, Visits, and Visit Ratio of each referer source, and you can filter data by time range.
Prerequisites
An Alibaba Cloud account. If you do not have one, sign up and complete real-name verification.
You have activated OSS, created a bucket, and uploaded resources to the bucket.
Procedure
Step 1: Activate CDN and add an accelerated domain
Log on to the Alibaba Cloud CDN console.
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 users will use to access content. For example,
image.example.com.Business Type: We recommend that you select Image and Small File.
Region: Select the regions where you want to accelerate content delivery. For example, select Chinese Mainland Only.
NoteIf this is the first time you add the domain name to Alibaba Cloud CDN, you must verify its ownership. Follow the instructions in the console to complete the verification. For more information, see Verify the ownership of a domain name.
Click Add Origin Server to configure an origin server. For Origin Info, select OSS Domain. From the Domain Name drop-down list, select the OSS bucket that you want to accelerate. Keep the default values for the other parameters and click OK.
After you configure the origin server, read and agree to the terms of service, and then click Next. Your request is submitted for review.
NoteIf your accelerated domain name does not require manual review, you can proceed to the next step. You can configure Recommended Configurations based on your business needs, such as cache TTL, bandwidth caps, and page optimization. These features can improve the cache hit ratio, security, and access performance of Alibaba Cloud CDN.
Wait until the Status of the domain name changes to Running. The CNAME value assigned to the accelerated domain name is displayed. In this example, the CNAME is
image.example.com.w.kunlunsl.com.After the domain name is added, in the domain list on the Domain Names page, find the CNAME column of the target domain name and copy the CNAME record value for the subsequent DNS resolution configuration. At this point, the CNAME Status is displayed as To Be Configured.
Step 2: Configure a CNAME record
After you add an accelerated domain name, Alibaba Cloud CDN assigns a CNAME to it. To enable acceleration, you must add a CNAME record with your DNS provider to map the accelerated domain name to its CNAME. This redirects user requests to CDN POPs.
The following steps show how to add a CNAME record if your DNS provider is Alibaba Cloud DNS. For information about other configurations, see Configure a CNAME record.
Use the Alibaba Cloud account that owns the accelerated domain name to log on to the Alibaba Cloud DNS console.
In the left-side navigation pane, click Domain Name Resolution. Find the domain name that you want to manage and click Settings in the Actions column.
Click Add Record to add a CNAME record.
Record Type: CNAME
Hostname:
imageRecord Value: Enter the CNAME that is assigned to your accelerated domain name, such as
image.example.com.w.kunlunsl.com.Keep the default values for the other parameters.
Click OK.
Step 3: Configure a CDN cache policy
CDN POPs cache content based on the cache policy that you configure, such as the cache TTL. After a POP caches a file, the POP can directly serve subsequent requests for the same file. This reduces latency and improves resource access efficiency. If a requested file is not in the cache or has expired, the POP sends an origin request to the OSS bucket to retrieve the latest version of the file. You can configure the cache TTL for static resources by directory or file extension based on your business requirements.
If you have already configured a cache TTL using the Recommended Configurations when adding the accelerated domain name, the default cache TTL for all resources in the directory is one month. You can adjust this setting based on your business needs.
-
Log on to the CDN console.
In the left-side navigation pane, click Domain Names.
-
On the Domain Names page, find the target domain name and click Manage in the Actions column.
In the left-side navigation pane of the specified domain name, click Cache.
On the Cache Expiration tab, click Create Rule.
In the Create Expiration Rule dialog box, configure a cache rule based on your requirements.
Type: File Extension.
File Extension: Enter the file extensions of the files that you want to cache. This example uses JPG files.
Expire In: If your resources are static files that are infrequently updated, such as images or application packages, set the cache TTL to one month or longer. This can help reduce origin requests.
NoteBy default, when a CDN POP receives a static file from the origin server, it caches the file based on the configured cache TTL.
Weight: 99.
Click OK.
Step 4: Optimize image access performance
You can use features such as image editing and ignore parameters to improve response times for image requests.
(Optional) Step 5: Analyze user behavior by using operations reports and monitoring
Create an operations report
For an e-commerce website, you can create and subscribe to operations reports to analyze access patterns, such as PV/UV, user regions, and popular URLs. For example, you can use the Popular Referers report to evaluate the performance of your advertising campaigns. High traffic from a specific channel indicates that the campaign is effective, while low traffic may suggest that you should pause the campaign.
You must first customize the content of an operations report before it can be generated for statistical analysis.
CDN monitoring queries
The resource monitoring feature provides reports on metrics such as access traffic/bandwidth, origin request traffic/bandwidth, number of requests, and hit ratio. You can also export these reports.
The comparison feature on the Data Transfer/Bandwidth of Requests tab lets you select two different time ranges and compare traffic data between them. This helps you monitor the performance of your website's advertising and operations.
The Resource Monitoring page also provides the HTTPCODE and Origin HTTPCODE reports. You can filter data by conditions such as Tag Filter, Domain Name, Region, ISP, and Protocol Layer, and switch between the Bandwidth and Traffic views.