This tutorial demonstrates how to accelerate a simple e-commerce website by separating dynamic and static content with Edge Security Acceleration (ESA) Functions. It provides a walkthrough of the deployment and configuration, explaining how Functions work and how they can significantly improve your website's loading speed and user experience.
Workflow
To accelerate a website static and dynamic content separately, follow these steps:
Configure a website: Add your primary domain name to ESA.
Deploy static resources: Store image resources in Object Storage Service (OSS). Then, configure a domain name in ESA to access these images.
Deploy dynamic resources: Deploy a Python service on an Elastic Compute Service (ECS) server. Then, configure a domain name in ESA to accelerate dynamic requests.
Configure an edge function: Configure an edge function and assign a domain name to it, which provides fast page rendering responses.
Before you start
This tutorial uses the following example domain names: www.example.com for origin server, shopping.example.com as the accelerated domain name, and images.example.com as the domain for static resources. Replace these with your actual domain names. You can use the images and python scripts in File materials for a proof of concept (POC).
1. Configure your website
Add your website to ESA to accelerate its static and dynamic resources.
In the ESA console, choose Websites and click Add Website.
Enter your website, such as
example.com, and click Next.On the Select Location and DNS Setup page, select the region in the Location for Acceleration and Protection section, and select CNAME for DNS Setup, and click Next.
On the Select Plan page, either purchase a New Plans or select an Purchased Plans. Follow the on-screen instructions to complete the purchase.
Purchase a new plan
On the New Plans page, select a plan that suits your needs.

Bind an existing plan
If you have an existing plan, select it on the Purchased Plans tab.

In the ESA console, click Websites in the left navigation pane, and click the target website. On the Overview page, verify the ownership of the domain name.
Copy the Record Value of the TXT record.

In the Alibaba Cloud DNS console, choose in the left navigation pane. On the Public Zone tab, find the domain name of the target website and click Settings.
In the Settings section, click Add Record. Add a record with the following settings and click OK.
Configuration
Example value
Record Type
TXTHostname
_esaauthRecord Value
verify_a186***be8(The record value provided in the console)TTL
10 minutes
In the ESA console, go to the overview page of the target website and click Verify.
Successful verification: If ESA displays
Verification successful, the verification is complete.Failed verification: If ESA displays
Verification failed, check whether the previous step was performed correctly, adjust the settings, and click Verify again.
2. Set up static resources
2.1 Prepare the environment
Log on to the OSS console. Go to the Buckets page and click Create Bucket. Enter a Bucket Name. Keep the default settings for other parameters and click Create.

Select the bucket that you created. On the file list page, upload the required files. Unzip the image set from the File materials section and upload the images to the root directory of the bucket.
NoteWe recommend storing the image resources in the root directory of the OSS bucket.
2.2 Configure the domain name for static resources
In the ESA console, choose Websites. In the Website column, click the target site.
In the left navigation pane, choose . Add a DNS record. The following table shows the exmaple settings:
Configuration
Example value
Record Type
CNAMEHostname
imagesProxy Status
Proxied
Record Value
OSS
Access Type
Private Access (Same account)
Authorization
By default, private access for the same account is automatically authorized.
OSS Bucket
website-resources-shopping.*******.aliyuncs.comOrigin Host
Match Origin's Domain Name
TTL
Auto
For Record Type, select Images/Video and click Done.
After the DNS record is created, copy the Hostname and Record Value from the CNAME Configuration Guide page.

Go to the Alibaba Cloud DNS console. In the left navigation pane, choose . Find the domain name of the target website and click Settings.
In the Settings section, click Add Record. Add a record with the following settings and click OK.
Configuration
Example value
Record Type
CNAMEHostname
imagesRecord Value
images.example.com.**.*******.comTTL
10 minutes
Return to the CNAME Configuration Guide page from Step 4. In the CNAME Verification step, click Query. If the status is Effective, the CNAME record is successfully configured.
NoteThe CNAME record may take several minutes to take effect.
Test whether the image can be displayed by entering
http://{accelerated domain name}/1.pngin your browser.NoteIf a 404 error occurs, try modify the URL to access the file based on its directory path. For example, if your image is in the images directory instead of the root directory, access
http://{accelerated domain name}/images/1.png.
3. Deploy dynamic resources
3.1 Prepare the environment
Log on to the ECS console.
In the left navigation pane, choose Instances & Images > Instances. In the top menu bar, select the region where your instance is located. In this example, it is China (Hangzhou).
On the Instances page, click Create Instance. Then create an ECS instance refering to the following example:
Configuration | Example value |
Billing Method | Pay-As-You-Go |
Region | China (Hangzhou) |
Network and Zone | Default VPC, default vSwitch in the zone |
Instance | ecs.e-c1m1.large (2 vCPU 2 GiB) |
Image | In Public Image, select Alibaba Cloud Linux |
Image Version | Alibaba Cloud Linux 3.2104 LTS 64-bit |
System Disk Type | ESSD |
System Disk Size | 40 GiB |
Public IP Address | Select Assign Public IPv4 Address |
Bandwidth Billing Method | Pay-by-traffic |
Bandwidth | 5 Mbps |
Security Group | Create Security Group (In Enable IPv4 Port/Protocol, select |
Management Settings | Custom Password (Set your own password) |
3.2 Deploy dynamic resources
Log on to the ECS console.
In the navigation pane on the left, choose Instances & Images > Instances. In the top menu bar, select the China (Hangzhou) region.
On the Instances page, find the target instance and click the instance ID to go to the instance details page.
Click Remote Connection. Select Connect and click Sig In Now. Enter the logon password to log on to the instance.

Download the demo python scripts and product data from File materials. After you unzip the package, upload the two files to the ECS server.
Replace the domain name
images.example.cominItemInfo.jsonwith the accelerated domain name for static resources that you configured in Section 2.2.Then, in the upper-left corner, choose File > New File Manager Window > Upload File. Upload the two downloaded documents to the server.

In the Workbench console, enter the following command to start a HTTP server.
cd / # Go to the root directory. nohup python -m http.server 80 & #Start an HTTP service on port 80 in the background.Enter
http://<Public IP>/ItemsInfo.jsonin your browser to check whether the dynamic product information is returned correctly.
3.3 Configure the domain name for dynamic resources
In the ESA console, choose Websites. In the Actions column of the target site, click the icon and choose DNS Records.
In the left navigation pane, choose .
On the record list page, click Add Record. Configure the parameters as described in the following table and click Next.
Configuration
Example value
Record Type
A/AAAAHostname
www
Proxy Status
Proxied
Record Value
10.0.x.x (The public IP address of the target ECS instance)
TTL
Auto
For Record Type, select API and click Complete.
After the DNS record is created, click CNAME Configuration Guide. Copy the Hostname and Record Value.
NoteDo not close the current page. You need to return to this page in Step 8 to verify whether the CNAME record has taken effect.

Go to the Alibaba Cloud DNS console. In left the navigation pane, choose . Find the domain name of the target site and click Settings.
In the Settings section, click Add Record. Add a record with the following settings and click OK.
Configuration
Example value
Record Type
CNAMEHostname
wwwRecord Value
www.example.com.**.*******.com(The Record Value from the CNAME Configuration Wizard)TTL
10 minutes
Return to the CNAME Configuration Wizard page from Step 5. In the CNAME Verification step, click Query. If Effective is displayed, the CNAME record is successfully configured.
NoteThe CNAME record may take several minutes to take effect.
4. Configure an edge function
4.1 Create an edge function
Log on to the ESA console. In the left navigation pane, choose .
On the Functions and Pages page, click Change in the Account Information area on the upper-right.
In the Change Plan dialog box, select Paid and click OK.
Click Create. Select Hello World from Function Templates and click Next.
Enter a Function Name. Add a description and click Submit.
Add an endpoint for the edge function.
In the left navigation pane, choose . On the edge function list page, click the target function.
On the function details page, switch to the Domains tab and click Add Domain Name. Assign the endpoint
shopping.example.comto the function and click OK.In the domain name binding area, find the edge function domain name that you created. In the Actions column, click View DNS Records. Copy the CNAME value of the edge function domain name.

Log on to the Alibaba Cloud DNS console. In the left navigation pane, choose . Find the domain name of the target website and click Settings.
In the Settings section, click Add Record. Add a record with the following settings and click OK.
Configuration
Description
Example value
Record Type
Select the type to which the domain name points.
CNAMEHostname
Enter the host record based on the domain name prefix.
shoppingRecord Value
Enter the CNAME value corresponding to the edge function domain name.
shopping.example.com.**.*******.comTTL
The update period of the domain name. Keep the default value.
10 minutes
Refresh the DNS record page and check whether the CNAME Status for the edge function domain name has changed from To Be Configured to Configured.
NoteThe CNAME record may take several minutes to take effect. If it does not take effect immediately, wait a few minutes.
4.2 Configure an edge certificate
ESA supports HTTPS encryption. You can configure an SSL certificate in ESA and enable SSL/TLS to encrypt data transmission between clients and ESA POPs. For this solution, we recommend that you request a free certificate. For more information, see How to configure an edge certificate.
In the ESA console, click Site Management on the left. On the Site Management page, click the target site.
On the target site management page, choose in the navigation pane on the left.
In the Edge Certificate section, find Enable SSL/TLS and click the switch on the right to enable this feature.

In the Edge Certificate section, find Certificate Management and click Request Free Certificate. Configure the parameters as described in the following table and click OK.
Configuration
Description
Example value
Certificate Authority
Keep the default value.
Let's EncryptCertificate Domain Names
Enter the static resource domain name, dynamic resource domain name, and edge function domain name from the previous steps.
images.example.comwww.example.comshopping.example.comThe free certificate application takes about 5 to 10 minutes. After the certificate is issued, it is automatically deployed to the ESA platform.
4.3 Configure the origin protocol and port
After the SSL certificate is configured, ESA uses the same protocol as the client request (HTTPS) for origin fetch by default. However, the origin server in this demo does not support HTTPS, and an HTTPS request to the origin server will fail. Therefore, you must specify HTTP as the origin protocol in ESA.
In the ESA console, click Website on the left and click the target site.
On the Website page, choose in the left navigation pane.
In the Origin Certificate section, find Origin Protocol and Port and click Configure. Configure the parameters as described in the following table and click OK.
Configuration
Description
Example value
Origin Protocol
Because the origin server does not support HTTPS, select
HTTP.HTTPHTTP Port
Keep the default value
80.80
4.4 Test and publish the edge function
Log on to the ESA console, and in the navigation pane on the left, choose .
On the edge function list page, select the target function.
On the edge function details page, switch to the Code tab. Use the following JavaScript code and replace the
urlPrefixvariable with the origin domain namewww.example.com. Then, click Save.async function handleRequest(request) { const urlPrefix = 'www.example.com'; // The request URL for the HTML file const staticDataUrl = 'http://' + urlPrefix + '/index.html'; // The request URL for the dynamic data const dynamicDataUrl = 'http://' + urlPrefix + '/ItemsInfo.json'; // Use the Cache API to query the page skeleton data const htmlCache = await cache.get(staticDataUrl); let html = ''; if (htmlCache === undefined) { const htmlResponse = await fetch(staticDataUrl); html = await htmlResponse.text(); await cache.put(staticDataUrl, new Response(html, { headers: [["cache-control", "max-age=1000"]] })); } else { html = await htmlCache.text(); } // Fetch the product data from the origin server const jsonResponse = await fetch(dynamicDataUrl); const json = await jsonResponse.json(); // Encapsulate the dynamic data into div blocks let itemsHtml = ''; for (const item of json.data) { const itemHtml = ` <div class="bg-white overflow-hidden shadow rounded-lg"> <div class="p-4"> <img class="h-48 w-full object-cover" src="${item.image}" alt="Placeholder image of a product"> <h3 class="mt-2 text-gray-900 text-sm font-medium">${item.title}</h3> <div class="mt-4"> ${item.originalPrice}${item.discountPrice}In the code editor, click Request in the upper-right corner to perform a local test. The logs are displayed in the lower-left section of the editor.
After the local test is successful, click One-click Release to deploy the code to the production environment.
5. Verify and clean up resources
5.1 Verify the demo
After you publish the edge function, verify the result in the following ways:
Open a browser and access the edge function domain name that you created in Section 4.1 (https://<Your edge function domain name>).
Check whether the page loads correctly and whether the product information is dynamically rendered.
Use browser developer tools to view network requests. Confirm that static resources result in a cache hit and that dynamic data is accelerated through POPs.


5.2 (Optional) Clean up resources
This demo involves creating multiple resource instances. If you no longer need these resources, release them to avoid charges:
Delete the website from ESA.
Log on to the ESA console. In the left navigation pane, click . Find the website that you want to delete and click Delete in the Actions column.
Delete the edge function.
In the ESA console, choose in the left navigation pane. Click the function that you want to delete and click Delete in the Basic Information tab.
Release the ECS instance.
Log on to the ECS console. On the Instances page, find the target instance. In the Actions column, choose Release. Release the instance as prompted.
Delete the security group.
Log on to the ECS console. On the Security Groups page, find the target security group. In the Actions column, click Delete. Delete the security group as prompted.