CDN Purge vs. Prefetch: Which Comes First When Releasing New Assets?
When releasing new assets, purging invalidates old cached content, while prefetching retrieves cacheable assets in advance. Neither operation publishes new files to your origin. With new, content-hashed filenames, the usual sequence is to upload and verify the assets, prefetch as needed, then switch page references. When overwriting the same URL, update and verify the origin first, purge the old cached content, then validate and prefetch once invalidation has taken effect.
This involves three main layers: origin files and deployment status, CDN caches, and browser caches. The first things to verify are not whether someone clicked the prefetch button, but whether the origin consistently returns the correct version, which cache key corresponds to the URL users actually request, and when entry pages start referencing the new assets. Deployments across multiple origins, query parameter rules, tiered caching, and Service Workers can all affect the sequence or verification method.
The most important distinction is this: for an immutable new URL, prepare the asset before switching references; for an overwritten existing URL, make the origins consistent before invalidating cached content. Treating every release as a full-site purge followed by prefetching everything can unnecessarily expand the cold cache footprint and concentrate traffic on the origin.
What Purging and Prefetching Actually Change
Purging Changes Cache Validity, but Does Not Guarantee New Content Is Loaded Immediately
The purge, clear, or invalidate functions in a CDN console generally prevent cached content within a specified scope from being reused directly as fresh content. Implementations may delete objects, mark them as stale, or trigger subsequent revalidation. Features such as URL, directory, and tag purges, along with their matching scope, depend on the product and account configuration. Similar names do not guarantee identical behavior.
A completed purge therefore usually means that a control-plane task has finished according to the product's definition, not that every user has received the new content. The next request after a purge may still need to retrieve content from an upstream cache or the origin. If the origin has not been updated, old content can enter the cache again.
MDN's HTTP caching guide classifies CDNs as managed caches and notes that HTTP caching itself does not define a universal explicit deletion interface. In other words, CDN purging is a management capability provided by a particular product, not a standard command that browsers and all intermediate caches can execute together.
Prefetching Retrieves Assets in Advance, but Does Not Guarantee Existing Old Content Is Replaced
Prefetching typically involves the CDN initiating asset retrieval to prepare some cached content before application users arrive. Whether it fills edge nodes, upstream caches, or specific regions, respects existing cached content, or supports particular request headers depends on the implementation.
Do not interpret prefetching as unconditionally downloading content again from your origin and overwriting every copy. If a valid old cache entry still exists for the same URL, a prefetch task may retrieve that old content through the cache hierarchy or behave differently according to the provider's definition. Without an explicit product guarantee, prefetching cannot replace purging.
Prefetching is not a promise of permanent cache residency, either. Objects may still be evicted because of TTL expiry, capacity management, low request frequency, or other factors. Earlier is not necessarily better: schedule prefetching after origin verification and as close as practical to the expected start of traffic.
Comparison | Purging | Prefetching |
|---|---|---|
Main purpose | Invalidate cached content that should no longer be used | Prepare reusable assets in advance |
Typical targets | Overwritten files, updated entry pages, content that must be withdrawn | Static assets for a new version, popular files expected to receive traffic soon |
Publishes source files | No | No |
Guaranteed to retrieve new content | No; it depends on the subsequent retrieval path | No; it depends on the origin, cache layers, and task semantics |
Main risks | A larger cold cache footprint and concentrated origin traffic | Prefetching the wrong version, increased origin load, ineffective cache population |
Acceptance criteria | Whether the old version has stopped being reused within the target scope | Whether the target assets are correct and deliver the expected caching behavior |
Identify the Release Model Before Choosing the Sequence
Content-Hashed Filenames: Prepare Assets Before Switching the Entry Point
Suppose the current page references /assets/app.a1b2c3.js, and the new build produces /assets/app.d4e5f6.js. Because the URLs differ, the files can generally coexist. As long as the cache key distinguishes these two paths, the new file does not require removal of the old one to take effect.
The recommended sequence is:
Upload all scripts, stylesheets, fonts, and dependent assets for the new version to every storage location or origin that may serve origin fetches.
Check paths, file contents, content types, and cache policies against the build manifest, ensuring that no code-split bundles are missing.
Prefetch critical new assets according to expected traffic and origin capacity, then spot-check the results.
Switch the HTML, asset manifest, or other entry point so that new visits reference the new files.
If the entry point itself is cached by the CDN, purge only the entry points that need updating, and verify that both old and new pages can load their dependencies.
There is no contradiction in prefetching before purging here: you are prefetching new asset URLs and purging old entry-point URLs. Determine the sequence for each object rather than applying one button-click sequence to the whole site.
Keep old hashed files until they are no longer needed by old HTML, open pages, lazy loading, or the rollback window. Do not base deletion timing solely on the HTML TTL: a user may trigger an asynchronous module long after opening a page, and a Service Worker may retain an old asset manifest.
Overwriting the Same URL: Update the Origin, Then Purge and Prefetch as Needed
If you always use /assets/app.js, old and new content share the same URL, so existing caches may continue serving the old version. A safer workflow is to update all origins to a consistent state, verify correctness, and submit a precisely scoped purge. Once the task reaches the product-defined completed state, request the asset to verify it, then prefetch that URL as needed.
Do not purge first and upload gradually afterward. Ordinary user requests or prefetch requests arriving after the purge may retrieve the asset immediately. If some origins still hold the old version, that content can repopulate the cache.
Overwriting the same URL also has a limitation that CDN operations cannot resolve: browsers may still hold copies that have not expired. Even if the CDN has updated correctly, the browser may not make a network request. For scripts and stylesheets, if update correctness depends on clearing every user's local cache each time, prioritize versioned URLs rather than increasing purge frequency.
A New URL May Still Need Purging If It Previously Returned an Error
The assumption that a new path needs no purge holds only if it has no existing cache entry that must be removed. For example, a page might reference a file before it is uploaded, causing the initial request to return 404. If a cache layer is configured to cache that error, users may continue receiving it even after the file has been uploaded successfully.
In this situation, first ensure that the origin returns the correct file. Then check the target URL for negative caching, perform a precise purge if necessary, and verify or prefetch again. Do not assume that all CDNs cache 404 responses by default, or that prefetching automatically replaces an existing cached error response.
Before Deployment, Confirm You Are Targeting the Cache Keys Users Actually Use
Query Parameters Do Not Necessarily Isolate Versions
/assets/app.js?v=2 looks like a new address, but whether it is cached separately depends on whether the CDN includes the parameter in its cache key. Some configurations retain all parameters, some ignore them all, and others retain only allowlisted parameters. The origin, upstream caches, and edge rules may also handle them differently.
If your application uses parameters to switch versions, request both parameter values and compare the response bodies to check that the rules behave as expected. If parameters are ignored, prefetching the new parameter value may still hit the old object. If every random parameter is included in the cache key, it can instead create large numbers of duplicate objects and origin requests.
Content-hashed paths are therefore usually a better fit for frontend build artifacts. They make version boundaries clearer and simplify asset manifests, rollback mappings, and precisely scoped purges.
The Same Path May Have Multiple Response Variants
Compression, language, device rules, authentication information, and custom request headers can all affect the response or cache key. The Vary response header expresses response differences based on certain request headers, but how a CDN actually handles it also depends on product support and custom rules.
If a prefetch request does not include a particular language or compression request header, do not assume that the corresponding user-facing variant is ready. You also need to check whether a purge operation clears every variant of a URL. For image processing or parameter-generated assets, confirm whether derived objects fall within the same purge scope.
Before making changes, compile a list of what is actually delivered: hostnames, paths, parameters that affect content, required request headers, and expected response types. Do not simply copy filenames from source code and assume they cover every form of user access.
An Edge Miss Does Not Prove the Request Reached Your Origin
A request may pass through an edge cache, a regional cache, and a parent cache before reaching object storage or a web service. After an edge entry is invalidated, content may still be retrieved from an upstream cache. A cache-status header showing a miss must be interpreted for the relevant layer according to the product's definition; it does not by itself prove that the request reached your origin.
If old content repeatedly appears after a purge, investigate upstream cache rules, origin request logs, request identifiers, and content hashes. In particular, when an edge purge succeeds but content remains old, check the actual origin target and upstream content next rather than immediately expanding to a full-site purge.
Verify the Origin Before Purging or Prefetching
All Origins Must First Converge on the Same Version
A single origin hostname may point to multiple web servers or storage endpoints, or use primary and backup origins. Verifying one server does not prove that the entire origin pool is ready. If prefetching selects different backends at different times, inconsistent versions can enter the cache.
Confirm consistency using controlled deployment status, build identifiers, and content hashes from each backend. Prefer complete version directories or atomic switches when uploading assets to avoid requests reading partially uploaded files. If the infrastructure does not support atomic deployment, at least upload all dependencies first, verify them, and only then update the entry point.
Also verify that the response is the file your application expects. An HTTP 200 response may contain an application fallback page, login content following an authentication redirect, or an error wrapper. The status code alone is not enough. Scripts should have an appropriate content type, and file hashes should match the build artifacts. For large assets, also check the length and the range-read behavior actually used.
Compare Against the Origin While Preserving Host and TLS SNI
The following example compares the same HTTPS asset retrieved through the CDN and directly from a specified origin. Run it only in an authorized environment with access to the origin. 203.0.113.10 is a documentation example address and cannot be used directly for real verification. Both requests use the same URL, GET method, and request headers, and request an uncompressed representation to reduce interference when comparing response-body hashes.
curl --silent --show-error \
--connect-timeout 5 --max-time 30 \
-H 'Accept-Encoding: identity' \
-D edge.headers -o edge.body \
-w 'status=%{http_code} remote_ip=%{remote_ip} ttfb=%{time_starttransfer} total=%{time_total}\n' \
'https://www.example.com/assets/app.d4e5f6.js'
curl --silent --show-error \
--connect-timeout 5 --max-time 30 \
--resolve 'www.example.com:443:203.0.113.10' \
-H 'Accept-Encoding: identity' \
-D origin.headers -o origin.body \
-w 'status=%{http_code} remote_ip=%{remote_ip} ttfb=%{time_starttransfer} total=%{time_total}\n' \
'https://www.example.com/assets/app.d4e5f6.js'
sha256sum edge.body origin.body
--resolve specifies the connection address while retaining the hostname in the URL, keeping Host and TLS SNI consistent. This makes it more suitable for HTTPS comparisons than accessing the origin IP directly. If the origin accepts only authenticated CDN origin requests or a dedicated access path, do not relax public access restrictions for testing. Use an approved verification environment instead, and check whether a proxy affects the specified connection target.
Matching hashes prove only that the two response bodies retrieved in this test are identical. You must still compare them against the release build manifest to avoid a situation where both copies are old. If the hashes differ, inspect status codes, response types, redirects, and content transformations before concluding that an old version is cached. The example does not automatically follow redirects. If you receive a 3xx response, first confirm that its destination is expected rather than treating the redirect response as the asset itself.
time_starttransfer is the cumulative time from the start of the request to the first byte, including earlier stages such as resolution and connection establishment. It is not pure origin processing time. Likewise, time_total does not represent a complete page load. These timings are primarily useful for spotting obvious anomalies; content correctness remains the priority for release acceptance.
Cache Policies Determine How Much Purging Can Solve
Immutable Assets and Entry Pages Need Different Policies
For content-hashed assets, consider a longer freshness lifetime and immutable, provided that content at the same URL truly will not be overwritten. HTML entry pages that need timely updates should use a shorter shared-cache lifetime or require revalidation before each reuse.
For example, a public entry page with no personalized content could use Cache-Control: public, max-age=0, s-maxage=60, must-revalidate: the browser receives no additional freshness lifetime, while shared caches can reuse the response within the example period. The 60 seconds here is only a configuration example, not a universal recommendation. It means accepting some propagation delay for the entry page even without a purge.
If the application requires validation before each reuse, consider Cache-Control: no-cache. It does not prohibit storage; it requires validation before reuse. no-store is the directive that says the response should not be stored. s-maxage applies to shared caches, while immutable suits assets that will not change during their freshness lifetime. See the Cache-Control directive reference for these distinctions.
The above applies only to content confirmed to be public. Do not apply the same policy directly to login pages, user profiles, or responses that vary by Cookie. If origin response headers conflict with CDN console rules, verify which takes precedence in practice. Changing origin response headers also does not automatically rewrite existing browser cache entries.
Correct Revalidation Prevents Old Content from Becoming Fresh Again
If a purge invalidates content and then relies on revalidation, the cache may send an upstream request with If-None-Match or If-Modified-Since. An upstream 304 response usually means reusing the existing response body rather than transferring a new file.
If file contents change but validators do not change correctly, the upstream may incorrectly return 304, allowing old content to remain in use. After overwriting the same URL, check whether ETag and Last-Modified behave correctly for your deployment method. A 304 response is neither inherently an error nor proof that the version has updated.
For important assets, content hashes and build manifests provide more direct acceptance criteria. Version identifiers can help with diagnosis, but if they are generated by separate configuration rather than deployed atomically with the file, they can misleadingly indicate a new version while the file is still old.
How to Verify That Purging and Prefetching Meet the Release Goal
Distinguish Successful Submission, Task Completion, and Correct Delivery
An accepted management API request means only that the task has entered the processing workflow. Task completion must be interpreted according to the product's defined scope. Actual application acceptance also requires that user-facing URLs return the correct content, entry points and dependencies are compatible, and no persistent old versions or error responses remain under key network conditions.
Do not interpret a task showing 100% as proof that all users, address families, and cache variants have been verified. For prefetching, also check for individual URL failures, redirects, authentication failures, and uncacheable responses. Even a successful task may not create a reusable cache entry if the resource returns no-store or matches a cache-bypass rule.
Release records should link at least the build version, target URLs, purge or prefetch task identifiers, submission and completion times, and content verification results. A clearly defined time window is necessary to correlate request logs with release actions.
Use Consecutive GET Requests to Inspect Content, Not a Single Response Header
You can make a small number of sequential GET requests for the same asset from the same network egress, retaining each response's headers and body. The three requests below are a minimal spot-check example, not evidence of regional coverage or a statistical conclusion. The test changes cache state, and the first request may already populate the cache.
for i in 1 2 3; do
curl --silent --show-error \
--connect-timeout 5 --max-time 30 \
-H 'Accept-Encoding: identity' \
-D "sample-${i}.headers" -o "sample-${i}.body" \
-w "sample=${i} status=%{http_code} remote_ip=%{remote_ip} total=%{time_total}\n" \
'https://www.example.com/assets/app.d4e5f6.js'
sleep 2
done
sha256sum sample-*.body
Review the response-body hashes, status codes, Cache-Control, validators, and product-defined cache-status headers together. Age can help assess response age, but its absence or any particular value cannot independently prove a cache hit or miss. Different requests may also reach different cache instances.
Do not substitute a successful HEAD request for GET content verification, and do not casually append random parameters or force-revalidation request headers during formal spot checks. These actions may change the cache key or normal request behavior. They are useful for separate diagnostic comparisons, not for proving that the ordinary user request path is correct.
Choose the Next Step Based on Results Instead of Repeatedly Clearing Caches
Observation | First things to investigate | Next step |
|---|---|---|
Both the origin and CDN return old content | Incomplete deployment or an incorrect origin target | Check the origin pool, deployment directory, and actual files |
The origin is correct, but some CDN requests still return old content | Purge scope, variants, upstream caches, or inconsistent origins | Narrow down the differences using request conditions and logs |
The CDN is correct, but the original browser still shows old content | Browser cache, Service Worker, or references from an old page | Check resource sources and initiators in developer tools |
Prefetching succeeds, but ordinary requests continue reaching the origin | Uncacheable assets, different keys, or a cache layer outside the task scope | Check cache eligibility, request headers, and task coverage |
The status code is 200, but page execution fails | Incorrect response body, missing code-split bundles, or incompatible versions | Check content and dependencies against the build manifest |
To observe regional differences, you can use CdnChart's website speed test as a supplementary view of access performance, but probe results cannot replace build hashes and application validation. Record the region, carrier, egress type, and whether IPv4 or IPv6 was used for each spot check. Results from a cloud server's network egress do not represent local residential broadband or mobile network experience.
Record timeouts and failures separately. Do not silently remove them from samples and then report that everything is normal. A single successful request proves success only at that time, from that egress, and under those request conditions. It does not prove consistency across the entire distribution scope.
Prefetch Within the Origin's Capacity Budget: More Is Not Always Better
A full purge creates many cold objects at once, while prefetching everything can concentrate their retrieval into an earlier window. Combined with real user traffic, this may place more pressure on the origin than the release would naturally generate. Request coalescing or upstream caching may reduce duplicate fetches, but do not assume that this protection exists for every path, object, or failure scenario.
A more controlled approach is to prefetch critical scripts, stylesheets, fonts, and known popular assets needed for the initial viewport first, then handle large files with more dispersed demand. Proceed in small batches while monitoring origin request rate, concurrency, outbound bandwidth, error rate, and storage read latency. Compare these metrics with normal baselines and available capacity, then adjust the size and spacing of subsequent batches rather than applying an unverified, uniform concurrency setting.
For large files, specifically confirm whether prefetching retrieves the complete object, whether users make Range requests, and whether partial responses can reuse prefetched data. A successful ordinary GET prefetch task does not automatically prove readiness for every range request.
If origin latency and errors rise together, pause subsequent prefetch batches, retain the verified working entry point, and investigate capacity. Do not keep expanding the purge scope. This is also why releases usually purge only entry points or fixed URLs whose content changed, rather than all unchanged hashed assets. For more guidance on defining the scope, see which URLs to purge after a release.
Rollbacks Also Require Dependencies to Be Ready Before Switching the Entry Point
Rolling back versioned assets is usually more straightforward: confirm that the old assets remain accessible, switch the entry point back to the old version, and perform any necessary purge of the cached entry point. If the old files are still available, there is no need to delete new-version assets to roll back. New pages that are already open may still need them.
Rolling back an overwrite at the same URL requires redeploying the old file to every origin, verifying consistency, purging the target URL, and then validating and prefetching as needed. This is effectively another release and remains subject to the same limitations imposed by fresh browser cache entries.
If you need to change cache rules temporarily, record the original values, restrict changes to the target path, perform a minimal initial validation, and prepare restoration steps. Do not disable the WAF, expose the origin publicly, or remove authentication just to make prefetching succeed. Use product-supported security mechanisms for signed URLs and protected assets so that short-lived credentials are not treated as long-term, publicly shareable resources.
Finish with a Release Acceptance Checklist
An auditable release should answer the following questions:
Have all assets been uploaded, and do all backends that may serve origin fetches return the same build?
Do new assets use distinct URLs, and are parameters and request headers included in the intended cache keys?
If existing URLs were overwritten, was the purge submitted only after origin verification, and was its scope confirmed?
Was prefetching limited to necessary objects, and were failures and origin load checked?
Was the entry point switched only after dependencies were ready, and do old pages and lazy-loaded modules still have accessible dependencies?
Are content hashes, status codes, and application execution correct, and were browser and Service Worker paths spot-checked?
Are the assets, entry-point versions, and original rule values needed for rollback still retained?
Which operation comes first ultimately depends on whether the URL changes. For new hashed assets, the usual sequence is verification, prefetching as needed, then switching and purging the entry point. For an overwrite at the same URL, update the origin first, then purge, verify, and prefetch as needed. What needs to be standardized is not the order of two buttons, but the dependencies between origin consistency, cache invalidation scope, entry-point switching, and content acceptance checks.
- CDN purge and prefetch
- CDN purge and prefetch sequence
- new asset release workflow
- CDN cache purge verification
- static asset versioning
- CDN prefetch origin load
- browser cache updates