Learn how to use Functions and Pages to accelerate website rendering by separating static and dynamic content. This guide uses a sample e-commerce site to show how Functions and Pages renders pages at edge POPs for faster load times.
Solution overview
Complete these steps to separate and accelerate static and dynamic content:
-
Configure an ESA site: Add your primary domain name to ESA to enable acceleration for the domain name.
-
Deploy static resources: Store image resources in OSS and configure an accelerated domain name in ESA to access these resources.
-
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: Configure a function and assign a domain name to it. The function helps deliver faster page rendering responses.
Notes
Replace these example domain names with your actual domain names: www.example.com (origin), shopping.example.com (accelerated), and images.example.com (static resources). When you perform the steps in this topic, you must replace these example domain names with your actual domain names.
1. Configure a site
Add your site to accelerate its static and dynamic resources.
-
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.

-
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: If the system displays a
Verification successfulmessage, the verification is complete.Failed verification: If the system displays a
Verification failedmessage, check that you performed the previous step correctly and adjust the settings as needed. After making corrections, 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 then click Create Bucket. Enter a Bucket Name, keep the default settings for other parameters, and then click Create.

-
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 accelerated domain for static resources
-
In the ESA console, choose Websites. 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 (Same-account)
Authorization
Private access for the same account is authorized by default.
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.

-
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.In the upper-left corner, choose File > Open New File Management > Upload File to upload the two 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 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 domain name to which you want to map the record.
CNAMEHost record
Enter the host record based on the domain name prefix.
shoppingRecord value
Enter the CNAME value of the edge function domain name.
shopping.example.com.**.*******.comTTL
The update cycle of the domain name. 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 supports HTTPS via SSL/TLS to encrypt client-to-POP requests. 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 resource, dynamic resource, and edge function domain names that you configured in the preceding steps.
images.example.comwww.example.comshopping.example.com -
Certificate issuance takes 5 to 10 minutes. After issuance, the certificate is automatically deployed to ESA.
4.3 Configure origin protocol and port
By default, ESA uses the client protocol (HTTPS) for origin fetch. Because the origin server in this example does not support HTTPS, configure ESA to use HTTP for origin fetch.
-
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
Because the origin server does not support HTTPS, select
HTTP.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 the edge function, verify the result:
-
Open a browser and access the edge function domain name that you created in Section 4.1 (for example, https://<your_edge_function_domain_name>).
-
Check whether the page is loaded and whether product information is dynamically rendered.
-
Use browser developer tools to view network requests and confirm that static resources are served from the cache and that dynamic data is accelerated by POPs.
-


5.2 Clean up resources (Optional)
If you no longer need these resources after testing, delete them to avoid further 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 |