Clearing a CDN cache removes stored copies of your website’s files from a content delivery network’s edge servers. This can help when visitors still see an old page, image, stylesheet, script, or other asset after you have updated it. The exact steps depend on your CDN provider, but the general process is to identify the affected content, request a purge or invalidation, and verify that the updated version is being served.
Before you clear the cache, remember that a purge does not change your website files or fix the source of an incorrect response. It simply asks the CDN to fetch fresh content from your origin the next time it receives a request. The guide below explains how to clear a CDN cache safely, choose between purging one file and purging everything, and troubleshoot updates that still do not appear.
What Does Clearing a CDN Cache Do?
A CDN stores cached copies of content on servers located closer to your visitors. When someone requests a cached file, the CDN can deliver it without contacting your origin server. This usually improves loading speed and reduces traffic to your website’s hosting environment.
When you update a file, the CDN may continue serving its older cached copy until that copy expires or is removed. Clearing the CDN cache—also called purging or invalidating the cache—tells the network to stop using selected stored content. The next request will generally cause the CDN to retrieve a fresh copy from the origin.
The process affects only the content and cache layers covered by the purge. For example, clearing a CDN cache may not clear a visitor’s browser cache, a server-side application cache, or a separate page-cache plugin. If an old version remains visible, more than one cache may need attention.
Choose What You Need to Purge
Most CDN providers offer a few ways to clear cached content. Choose the narrowest option that solves the problem. A targeted purge is usually faster and less disruptive than clearing the entire cache.
-
Purge one URL: Removes the cached version of a specific page or file, such as
https://example.com/images/banner.jpg. - Purge multiple URLs: Clears a selected set of pages or assets in one request. Providers may set a limit on how many URLs you can submit at once.
- Purge by tag or surrogate key: Removes items associated with a label, such as all product pages for one category. This option is available only when your site and CDN are configured to use it.
- Purge a path or wildcard: Clears a group of files, such as everything under a directory. Wildcard support and syntax vary by provider.
- Purge everything: Removes all eligible cached content for a site, zone, or distribution. This is the broadest option and should generally be reserved for emergencies or major site-wide changes.
If only one image or stylesheet is outdated, avoid purging the entire cache. A full purge can increase requests to your origin because the CDN must rebuild its cache as visitors return. On a busy site, that extra load can slow pages or put pressure on your hosting infrastructure.
How to Clear a CDN Cache from the Provider Dashboard
The simplest way to clear a CDN cache is usually through your provider’s dashboard. Provider names, menu labels, and available purge options differ, but the general workflow is similar.
- Sign in to your CDN account. Open the account or project associated with the website that is showing outdated content.
- Select the correct site or distribution. Check the domain, environment, and configuration carefully. A staging site and a production site may have separate caches.
- Open the cache controls. Look for a section named Cache, Caching, Purge, Invalidation, or similar.
- Choose the purge scope. Select a specific URL, a list of URLs, a tag, a path, or the full cache, depending on what is available and what needs updating.
- Enter the exact URL or identifier. Match the public URL visitors request, including the correct hostname and path. Follow your provider’s instructions about query strings, protocols, and wildcards.
- Submit the request. Review the scope before confirming, especially if you selected an option that clears everything.
- Wait for the purge to propagate. The dashboard may show a queued, processing, or completed status. A completed request does not always mean every edge location has refreshed instantly.
- Test the updated content. Open the page in a private browser window or use a command-line request to check what the CDN is returning.
For example, if you changed a logo at https://example.com/assets/logo.svg, purge that asset rather than every page on the site. If you changed the layout across many pages, you may need to purge the relevant page URLs or use a tag-based purge if your setup supports it.
Clear a CDN Cache with an API or Command-Line Tool
If you manage frequent deployments or multiple websites, using a CDN API can make cache clearing faster and more consistent. Most major providers offer an API endpoint or command-line tool for submitting purge or invalidation requests. The exact endpoint, authentication method, request format, and permissions depend on the provider.
A typical API workflow is to create an access token with the minimum permissions needed, identify the correct site or distribution, and submit the URLs or cache keys to invalidate. Store tokens securely in your deployment platform’s secret-management settings. Do not place private credentials in public JavaScript, a public repository, or a page visitors can access.
For an automated deployment, you can add a purge step after new files are uploaded and verified at the origin. Make sure the deployment targets the correct environment and that the purge request succeeds before treating the release as complete. Monitor API responses and logs, because a request may be rejected if a token lacks permissions, the resource identifier is wrong, or a provider’s request limit has been reached.
Do not copy an API command from another CDN without checking its documentation. Providers use different authentication schemes and purge syntax, and a command intended for one account or distribution may affect the wrong site.
Use Cache-Control Headers to Reduce Future Purges
Purging fixes cached content that is already stored, but a good caching strategy can reduce how often you need to clear it. Your origin server can send HTTP cache headers that tell browsers and CDNs how long content may be stored and whether it must be revalidated.
Common directives include max-age, which sets a freshness period, and no-cache, which generally allows storage but requires validation before reuse. no-store asks caches not to store the response and is intended for content that should not be cached. The correct directive depends on the content, CDN configuration, and privacy requirements. A CDN may also apply its own rules, so confirm how your provider handles origin headers.
For static files that change during a release, versioned filenames are often more reliable than repeatedly purging the same URL. For example, a stylesheet named styles.v2.css can have a long cache lifetime, while a new release uses styles.v3.css. Because the URL changes, the CDN treats it as a new asset. This approach is called cache busting and is commonly managed by website build tools.
Use shorter cache lifetimes for content that changes frequently, and longer lifetimes for files that rarely change. For pages that include personalized or sensitive information, configure caching carefully so private responses are not served to other visitors.
How to Check Whether the CDN Cache Was Cleared
After submitting a purge, check the response that visitors receive rather than relying only on the dashboard status. Start with the exact URL that was outdated and test it from a private browser window. This can help reduce the influence of your browser’s local cache, although it does not prove that every CDN location has refreshed.
You can also inspect response headers with your browser’s developer tools or a command-line request. Depending on the provider, headers may indicate whether a response was a cache hit or miss, how long it was stored, or which edge location served it. Header names vary, so consult your provider’s documentation rather than assuming one particular header is always present.
Compare the response with the version available directly from your origin, if your provider and security setup allow a safe origin test. Do not expose an origin server unnecessarily or bypass protections in a way that could put your site at risk. If the origin itself returns the old file, the CDN may be behaving correctly; update the origin content first, then purge or wait for expiration.
Why Is the Old Content Still Showing?
If a CDN purge appears successful but visitors still see outdated content, check the other parts of the delivery path. A browser, reverse proxy, hosting platform, application, or website plugin may be caching a separate copy. Try a different browser or network, and inspect the response headers to identify which layer is serving the response.
Also check that you purged the exact URL visitors are requesting. These may be treated as different resources:
-
httpandhttpsversions of a page -
www.example.comandexample.com - Different file paths, capitalization, or trailing slashes
- URLs with different query strings, depending on the CDN’s cache-key settings
- Different versions of an asset, such as
app.jsandapp.min.js
Confirm that your site is using the CDN distribution or zone you purged. DNS changes, alternate domains, staging environments, and recently modified CDN configurations can make this less obvious than expected. If the purge is still processing, allow time for the provider to distribute the change. If it fails or takes unusually long, review the provider’s status page, purge limits, dashboard messages, and account permissions.
Common CDN Cache-Clearing Mistakes to Avoid
Clearing the whole CDN cache for a small update can cause unnecessary origin traffic and slower first requests. Purging too frequently can also undermine the performance benefit of caching. Whenever possible, invalidate only the affected URLs or use a tag-based approach that targets related content.
Another common mistake is purging before the new file has been uploaded. If the CDN fetches the origin immediately and the origin still contains the old version, the old content may be cached again. A safer sequence is to publish and verify the new origin content, then submit the purge if needed.
Finally, do not assume that a successful purge clears every cache between your origin and the visitor. Check the relevant layers, use cache headers intentionally, and keep a record of which URLs or tags were invalidated during a deployment.
Conclusion
To clear a CDN cache, sign in to your CDN provider, select the correct site or distribution, and submit a purge for the affected URL, group of files, tag, or entire cache. Use the smallest scope that solves the problem, then verify the response and allow time for the change to reach edge locations.
If the old version remains, check the origin, browser cache, website or hosting cache, exact URL, and CDN configuration. For fewer manual purges, use sensible cache headers and versioned filenames for frequently updated assets. These practices help you refresh content reliably while preserving the speed and efficiency a CDN is designed to provide.
Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.