All Products
Search
Document Center

CDN:Purge and prefetch resources

Last Updated:Dec 04, 2025

Purge instantly removes specified content from the CDN cache, forcing a retrieval of the latest version from your origin. Use this to ensure immediate content updates, apply configuration changes, or remove non-compliant materials without waiting for the cache to expire. Prefetch proactively loads your resources onto the CDN before peak traffic hits. This protects your origin server from overload and guarantees a fast, cached response for even the first wave of users during launches or high-demand events.

How purge and prefetch work

Resource purge

A purge operation sends a cache invalidation command to CDN POPs, rather than directly deleting files. When a POP receives the command, it marks the matching cached resources as "invalid" or "expired." The next time a user requests the resource, the POP detects the invalid cache, retrieves the latest version from the origin server, and serves it to the user while re-caching it.

Use cases

  1. Update and release content: After updating resources on your origin server, purge their URLs or directories. This ensures users receive the latest versions instead of stale content.

  2. Remove non-compliant content: If you delete non-compliant content from your origin server, it might still be accessible from the CDN cache. Use the URL purge feature to clear the cache and ensure the content is completely removed.

Resource prefetch

Prefetching prompts CDN POPs to retrieve resources from your origin server based on a provided URL list and cache them. This process differs from the origin server actively pushing content. Prefetching improves the first-visit loading speed for new resources or promotional pages and reduces back-to-origin traffic during high-traffic events, protecting your origin server.

Use cases

  1. Onboard Alibaba Cloud CDN: When you first start using Alibaba Cloud CDN, prefetch your popular static resources to the POPs. This improves initial access speed and enhances user experience.

  2. Support promotional campaigns: Before launching a major promotional campaign, prefetch all static resources for the campaign pages to the CDN POPs. When the campaign begins, the POPs directly serve all user requests for these resources, ensuring fast page loads.

  3. Publish installation packages or large files: Before releasing a new software version or update package, prefetch the resources to the CDN POPs. After the official launch, the POPs directly handle user download requests, which accelerates download speeds and reduces the load on your origin server.

Before you start

  • Permissions: If you use a RAM user, grant the cdn:PushObjectCache (for prefetch) and cdn:purgeObjectCaches (for purge) permissions. For more information, see Authorize a RAM user to prefetch and purge resources.

  • URL format: URLs with non-ASCII characters (like Chinese characters or spaces) must be UTF-8 percent-encoded.

Notes

  • Timing: Purge and prefetch tasks generate origin fetch traffic. We recommend that you perform large-scale tasks during off-peak hours.

  • Shared cache: If a domain uses a shared cache, a purge task on the primary or any associated domain invalidates the cache for all of them.

  • Rewrite URL: if the access URL for the domain name has been rewritten, POP uses the rewritten URL to generate a Cachekey, therefore use the rewritten URL for a purge or prefetch task.

Billing

The purge and prefetch features are free of charge.

However, both operations trigger CDN POPs to fetch resources from your origin server. This generates origin traffic and requests, which incurs fees. The billing standards depend on your origin server type:

  • If your origin server is Alibaba Cloud Object Storage Service (OSS), you are billed for the outbound traffic over the Internet and the number of requests with HTTP status codes 2xx and 3xx returned.

  • If your origin server is an Alibaba Cloud Elastic Compute Service (ECS) instance or another server, you are billed based on its network bandwidth or traffic.

Important

Large-scale purge or prefetch operations, especially within a short period, can increase origin fetch costs. Evaluate the potential cost impact before you proceed.

Procedure

Purge resources

  1. Log on to the CDN console.

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

  3. On the Purge/Prefetch tab, select Purge as the operation type.

  4. Select a purge method and submit the task.

    Purge method

    Instructions

    By URL

    Purpose: Invalidates the cache for one or more specific files.

    Procedure: In the Purge Content input box, enter the full URLs, including http:// or https://, with one URL per line. For example: https://www.example.com/static/image.jpg.

    By directory

    Purpose: Invalidates the cache for all content within a directory.

    Procedure: Enter the full directory URL, which must end with a forward slash (/). Example: https://www.example.com/static/.

    Note: This method performs a cache revalidation. To perform a forced purge on the entire directory, use the RefreshObjectCaches and set Force=true.

    By regular expression

    Purpose: To batch invalidate cached resources by matching URL paths with a regular expression.

    Procedure: Enter a URL that contains a regular expression. For example, https://www.example.com/static/[0-9][a-z].*.jpg

    Important: Use precise matching rules to avoid unintended, large-scale cache invalidation.

    Note: This method performs a cache revalidation. To perform a forced purge on the entire directory, use the RefreshObjectCaches and set Force=true.

  5. Click Submit. The system then starts the task.

    Note
    • You cannot cancel a purge task after it is submitted.

    • A purge task typically takes 5 to 6 minutes to take effect. If the cache expiration time for your resources is shorter than this duration, manual purging is not necessary.

    • If you enable auto CDN cache update in the OSS console, you cannot view the auto cache update tasks for OSS in the CDN/ console.

Prefetch resources

  1. Log on to the CDN console.

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

  3. On the Purge/Prefetch tab, select Prefetch as the operation type.

  4. In the Prefetch Content text box, enter the full URLs of the files that you want to prefetch, one per line. For example, https://www.example.com/install/package.zip. Prefetching folders is not supported.

  5. Click Submit. The system then starts to run the prefetch task.

    Note
    • You cannot cancel a prefetch task after it is submitted.

    • A prefetch task typically takes 5 to 30 minutes to complete, depending on the file size, number of files, and origin server performance.

Automated purge or prefetch

We recommend using automated purge and prefetch scripts for the following situations:

  • You manually submit tasks, resulting in high operational costs.

  • You have many URLs to process, which makes manual batch submission inefficient.

  • You need to monitor task status, which is time-consuming.

Verify results

  • Verify manually

    On the Records tab, you can view the detailed records and progress of your purge or prefetch tasks. A progress of 100% indicates task completion. Tasks with a large number of resources may take longer to complete.

    image

  • Verify by API

    Call the DescribeRefreshTaskById API to check whether a purge or prefetch task is complete.

  • Verify by command line

    Run the curl -I <resource_URL> command. The system displays the following result:

    image

    If the X-Cache header is in the response:

    • If X-Cache is HIT, the request hit the cache, and the prefetch was successful.

    • If X-Cache is MISS, the request did not hit the cache. The prefetch task is not complete or has failed. Prefetch the resource again.

    If the X-Cache header is not in the response:

    The resource is not accelerated by CDN. Add the domain name of the URL to Alibaba Cloud CDN and then prefetch the resource. For more information, see Get started with Alibaba Cloud CDN.

Quotas

Operation

Method

Quota

Manage or increase quotas

Purge

By URL

Up to 10,000 URLs per day per account

Quota management

By directory

  • Up to 100 directories per submission;

  • Up to 100 directories per minute per domain name

By regular expression

Up to 20 expressions per day per account

Prefetch

By URL

  • Up to 100 URLs per submission;

  • Up to 1,000 URLs per day per account

Reference: CDN cache purge mechanisms

Alibaba Cloud CDN provides two cache purge mechanisms, revalidation and forced purge, for different scenarios to help you manage cached content with flexibility and efficiency.

Revalidation (default CDN policy)

  • Use cases: Routine content updates, such as releasing new versions of static files.

  • Mechanism: Purging by directory or regular expression in the console use this behavior by default. When a CDN POP retrieves a resource from the origin, it includes the If-Modified-Since or If-None-Match request header. The origin server uses these headers to validate if the resource has been updated.

  • Result: If the resource on the origin server has not changed, the origin server returns a 304 Not Modified status code. The CDN POP continues to serve the old cached copy, which consumes no origin fetch traffic. This optimized method saves costs and reduces the load on your origin server.

Forced purge

  • Use cases: Urgent removal of non-compliant or incorrect resources, or scenarios where you need to force a network-wide update after fixing an incorrect Cache-Control header configuration.

  • Mechanism: To trigger a Forced Purge, call RefreshObjectCaches and set the Force parameter to true. Then the CDN POP unconditionally marks the cached resource as invalid.

  • Result: When the resource is next requested, the POP must retrieve a new version from the origin, even if the origin file is unchanged.

FAQ

Related API