Use Functions and Pages to separate static and dynamic content for faster page loads. A sample e-commerce site shows how Functions and Pages renders pages at edge POPs for faster load times.
Solution overview
To separate and accelerate static and dynamic content:
Configure an ESA site: Add your domain to ESA for acceleration.
Deploy static resources: Store images in OSS and configure an accelerated domain in ESA.
Deploy dynamic resources: Deploy a Python service on an ECS server and configure a domain name in ESA to accelerate dynamic requests.
Configure Functions and Pages: Create a function and assign a domain. The function renders pages at edge POPs for faster responses.
Before you begin
Replace these example domain names with your actual domain names: www.example.com (origin), shopping.example.com (accelerated), and images.example.com (static resources). Use your actual domain names throughout this guide.
1. Configure a site
Add your site to enable acceleration.
In the ESA console, choose Websites and click Add Website.
On the Enter Website page, enter your site, for example,
example.com, and click Next.On the Select Location and DNS Setup page, in the Location for Acceleration and Protection section, select the regions where your site requires secure acceleration services. For DNS Setup, select CNAME 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 navigation pane on the left. On the Site Management page, click the target site. On the Overview page, verify your domain ownership.
Copy the Record Value of the TXT record.
Log on to the console of your DNS provider (Alibaba Cloud is used in this example) and add a TXT record with the following parameters:
Type: TXT
Host:
_esaauthValue: paste the verification value you copied (it starts with
verify_)Request source: Default
TTL: 10 minutes (recommended)
Clean up unused TXT records so that the total record length does not exceed the limit and break DNS resolution.
In the Alibaba Cloud DNS console, choose Public DNS > Authoritative Domain Names from the navigation pane on the left. On the Authoritative Domain Names tab, find the domain name of the target site and click DNS Settings.
In DNS Settings, click Add Record. Add a record with these settings and click OK.
Parameter
Example value
Record type
TXTHost record
_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 site and click Verify.
Successful verification: A
Verification successfulmessage confirms completion.Failed verification: If
Verification failedappears, check the DNS settings and click Verify again.
2. Configure static resources
2.1 Prepare environment and resources
Log on to the OSS console, go to the Buckets page, and click Create Bucket. Enter a Bucket Name, keep other defaults, and click Create.
In this example, Bucket Name is set to
website-resources-shoppingand Region is set to China (Hangzhou).Select the bucket you created. On the Files page, decompress the product image set from Resource files and upload the images to the root directory of the bucket.
NoteStore image resources in the root directory of the OSS bucket.
2.2 Configure the accelerated domain for static resources
In the ESA console, select Websites, and in the Website column, click the target site.
In the left navigation bar, click , and add a DNS record based on the Record Type.
Parameter
Example value
Record Type
CNAMEHostname
imagesProxy Status
Enabled
Record Value
OSS
Access Type
Private Access (STS Temporary Token)
Authorization
Authorized by default for same-account access.
OSS Bucket
website-resources-shopping.*******.aliyuncs.comOrigin Host
Follow Origin Domain Name
Select Image/Video for the record type, and click OK.
After the DNS record is created, copy the Hostname and Record Value from the CNAME configuration wizard page.
When you add the record in the Alibaba Cloud DNS console, set Type to CNAME - Point the domain name to another domain name, enter the copied values in Host and Value, select Default for Request source, and keep TTL at 10 (recommended) minutes.
Go to the Alibaba Cloud DNS console. In the navigation pane on the left, choose Public DNS > Authoritative Domain Names. On the Authoritative Domain Names tab, find the domain name of the target site and click DNS Settings.
In DNS Settings, click Add Record. Add a record with these settings and click OK.
Parameter
Example value
Record type
CNAMEHost record
imagesRecord value
images.example.com.**.*******.comTTL
10 minutes
Return to the CNAME configuration wizard page from Step 4. In step 3. Verify the CNAME record, click Query. If the CNAME record has taken effect, the CNAME configuration is complete.
NoteThe CNAME record may take a few minutes to take effect.
Enter
http://<your_accelerated_domain_name>/1.pngin your browser to verify that the image is displayed.NoteIf a 404 error occurs, adjust the URL to match the image directory path. For example:
http://<your_accelerated_domain_name>/images/1.png.
3. Deploy dynamic resources
3.1 Prepare environment
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, click Create Instance. Then, create an ECS instance on the purchase page.
Parameter | Example value |
Billing method | Pay-As-You-Go |
Region | China (Hangzhou) |
Network and zone | Default VPC and default vSwitch in the zone |
Instance type | ecs.e-c1m1.large (2 vCPU, 2 GiB) |
Image | Select Alibaba Cloud Linux from Public Image. |
Image version | Alibaba Cloud Linux 3.2104 LTS 64-bit |
System disk type | ESSD cloud disk |
System disk size | 40 GiB |
Public IP | Select Assign Public IPv4 Address. |
Bandwidth billing method | Pay-by-data-transfer |
Peak bandwidth | 5 Mbps |
Security group | Create Security Group (In Open IPv4 Port/Protocol, select |
Management settings | Custom Password (Set your 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 via Workbench, and then click Log On Now. Enter the logon password to complete the logon.
Download the website code and product data from Resource files, decompress the package, and upload the two files to the ECS server.
In the ItemInfo.json file, replace
images.example.comwith the accelerated domain name configured in Section 2.2.Choose File > Open New File Management > Upload File to upload both files to the server.
In the Workbench console, run the following commands to start an HTTP server.
cd / # Go to the system root directory. nohup python -m http.server 80 & # Start an HTTP service on port 80 in the background.In your browser, enter
http://<your_public_ip>/ItemsInfo.jsonto verify that dynamic product data is returned.
3.3 Configure the accelerated domain for dynamic resources
In the ESA console, choose Websites. In the Actions column of the target site, click the icon and select DNS Records.
In the navigation pane on the left, choose .
On the record list page, click Add Record, configure the parameters, and then click Next.
Parameter
Example value
Record type
A/AAAAHost record
www
Proxy status
Enabled
Record value/origin
10.0.x.x (The public IP address of the target ECS instance)
TTL
Auto
Select API for the record type and click OK.
After the DNS record is created, copy the Hostname and Record Value from the CNAME configuration wizard page.
NoteKeep this page open. You will return to verify the CNAME record in Step 8.
Go to the Alibaba Cloud DNS console. In the navigation pane on the left, choose Public DNS > Authoritative Domain Names. On the Authoritative Domain Names tab, find the domain name of the target site and click DNS Settings.
In DNS Settings, click Add Record. Add a record with these settings and click OK.
Parameter
Example value
Record type
CNAMEHost record
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 step 3. Verify the CNAME record, click Query. If the CNAME record has taken effect, the CNAME configuration is complete.
NoteThe CNAME record may take a few minutes to take effect.
4. Configure Functions and Pages
4.1 Create Functions and Pages
Log on to the ESA console. In the navigation pane on the left, choose .
Click Create. For the creation method, select Function Templates. Select the
Hello Worldtemplate and click Next.Enter a Routine Name, add a description as needed, and then click Submit.
Add a domain name for Functions and Pages.
Log on to the ESA console. In the navigation pane on the left, choose .
On the Functions and Pages list page, click the target function.
On the function details page, switch to the Domain Name tab and click Add Domain Name. Assign the domain name
shopping.example.comto the edge function and click OK.In the domain binding area, find the edge function domain name you just created. In the Actions column, click View DNS Records. On the DNS record management page, copy the CNAME value for the edge function domain name.
Log on to the Alibaba Cloud DNS console. In the navigation pane on the left, choose Public DNS > Authoritative Domain Names. On the Authoritative Domain Names tab, find the domain name of the target site and click DNS Settings.
In DNS Settings, click Add Record. Add a record with these settings and click OK.
Parameter
Description
Example value
Record type
Select the type of the DNS record.
CNAMEHost record
Enter the host record based on the domain prefix.
shoppingRecord value
Enter the CNAME value of the edge function domain.
shopping.example.com.**.*******.comTTL
The DNS update cycle. Keep the default value.
10 minutes
Refresh the DNS record page and check whether the CNAME Status of the edge function domain name changes from To be configured to Configured.
NoteThe CNAME record may take a few minutes to take effect.
4.2 Configure an edge certificate
ESA encrypts client-to-POP requests with SSL/TLS. For this practice, apply for a free certificate. Configure an edge certificate.
In the ESA console, click Websites in the navigation pane on the left, and then click the target site.
On the management page of the target site, choose SSL/TLS > Edge Certificates from the navigation pane on the left.
In the Edge Certificates section, find SSL/TLS and click the switch to enable it.
In the Edge Certificates section, find Certificate Management and click Apply for Free Certificate. Configure the parameters and click OK.
Parameter
Description
Example value
Certificate authority
Use the default value.
Let's EncryptCertificate domain names
Enter the static, dynamic, and edge function domain names configured in previous steps.
images.example.comwww.example.comshopping.example.comCertificate issuance takes 5 to 10 minutes. The certificate is then automatically deployed to ESA.
4.3 Configure origin protocol and port
ESA uses HTTPS for origin fetch by default. Because the origin in this example does not support HTTPS, configure ESA to use HTTP instead.
In the ESA console, click Websites in the navigation pane on the left, and then click the target site.
On the management page of the target site, choose in the navigation pane on the left.
In the Origin Certificates section, find Origin Protocol and Port and click Configure. Configure the parameters and click OK.
Parameter
Description
Example value
Origin protocol
Select
HTTPbecause the origin does not support HTTPS.HTTPHTTP port
Keep the default value of
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 Functions and Pages list page, click the target function.
On the function details page, switch to the Code tab. Replace the
urlPrefixvariable with your origin domain namewww.example.com, then click Save.async function handleRequest(request) { const urlPrefix = 'www.example.com'; // The request URL of the HTML file. const staticDataUrl = 'http://' + urlPrefix + '/index.html'; // The request URL of the dynamic data. const dynamicDataUrl = 'http://' + urlPrefix + '/ItemsInfo.json'; // Use the Cache API to query 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 product data from the origin server. const jsonResponse = await fetch(dynamicDataUrl); const json = await jsonResponse.json(); // Encapsulate 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"> <span class="original-price">${item.originalPrice}</span> </div> <div class="mt"> <span class="text-gray-900 font-semibold">${item.discountPrice}</span> </div> </div> </div>`; itemsHtml += itemHtml; } // Replace #(itemsHtml) in the static HTML with dynamic data. const finalHtml = html.replace("#(itemsHtml)", itemsHtml); // Return the HTML page rendered at a POP to the browser. return new Response(finalHtml, { headers: { "content-type": "text/html;charset=UTF-8", }, }); } export default { async fetch(request) { return handleRequest(request); }, };Click Request in the upper-right corner to run a local test. Execution logs appear in the lower-left section.
After testing succeeds, click One-click Release to deploy the code to production.
5. Verify and clean up resources
5.1 Verify the solution
After publishing, verify the result:
Open a browser and go to the edge function domain (for example, https://<your_edge_function_domain_name>).
Verify that the page loads and product data renders dynamically.
Use browser developer tools to confirm that static resources are cached and dynamic data is accelerated by POPs.
If the verification succeeds, the page shows the women's clothing channel of the shopping mall: a search box at the top, category navigation tabs such as Dresses, T-shirts, Jeans, Coats, and Sportswear, and a grid of product cards. Each card shows the product image, the product name, the original price with a strikethrough, and the promotional price in red. This indicates that the product data was rendered dynamically at the edge POP.
In the DevTools Network panel, select a static resource request such as an image and check the Response Headers. The following fields confirm a CDN cache hit:
X-Site-Cache-Status: the value isHIT, which indicates that the resource was served from the edge POP cache.X-Swift-Cachetime: the value is3600, which indicates that the cache is valid for 3600 seconds.X-Swift-Savetime: the time when the resource was written to the cache.
5.2 Clean up resources (Optional)
If you no longer need these resources, delete them to avoid charges:
Delete the site.
Log on to the ESA console. In the navigation pane on the left, click Websites. On the Site Management list page, click Delete in the Actions column.
Delete the edge function.
In the ESA console, choose in the navigation pane on the left. On the Functions and Pages list page, click the target function. On the Basic Information tab, click Delete Routine.
Release the ECS instance.
Log on to the ECS console. On the Instance page, find the target instance. In the Actions column, choose Release and follow the on-screen instructions to release the instance.
Delete a security group.
Log on to the ECS console. On the Security Groups page, find the target security group. In the Actions column, click Delete and follow the on-screen instructions to delete the security group.
Resource files
Product image set | |
Website code and product data |