To set up a CDN for static files, you need five things working together: a cacheable origin, a dedicated hostname pointed at the provider with a CNAME, cache rules per asset class, TLS at the edge, and a tested purge and rollback path. That is how to set up a CDN without surprises. For a typical site, expect 60 to 90 minutes of hands-on work plus one DNS TTL (300 seconds if you lower it first) for cutover. This guide covers eight numbered steps, a cache rule table by asset type, validation checks with expected values, and a diagnostics and rollback runbook.
Under the HTTP caching semantics in RFC 9111, a content-hashed file served with Cache-Control: public, max-age=31536000, immutable can stay at the edge for one year and never needs a purge, because every new build ships under a new URL. As of 2026, that single header on fingerprinted JavaScript, CSS and fonts is the main lever for reaching the common 95% cache hit ratio target for immutable assets. Short TTLs are reserved for the few files that change in place.
Confirm these before you touch DNS. Each one prevents a specific failure later in this guide.
Split every path into three classes. Immutable covers hashed JavaScript, CSS, fonts and source maps. Low-mutation covers images, PDFs and marketing files that change occasionally under the same name. High-mutation covers avatars, runtime configuration files and user-generated images. Why: one TTL for everything either serves stale files or wastes the cache, and the class decides both the header and the purge strategy.
The CDN can only be as consistent as the origin. Audit these headers on one file from each class:
Why: identical URLs must return identical bytes regardless of which backend answers. Otherwise, the edge caches whichever variant it saw first.
Create a pull zone with your origin hostname, keep the origin Host header the origin expects, and enable origin shield if the provider offers it. That collapses misses from many edge locations into one upstream fetch. Turn on request coalescing so a burst of simultaneous misses for one object produces a single origin request. On BlazingCDN, origin shield and request coalescing are included on every plan, and Anycast CDN zones for static files are configured together with an engineer, with onboarding taking about one hour.
Lower the TTL on the existing record to 300 seconds a day ahead, then create the CNAME. The record looks like this:
static.example.com. 300 IN CNAME YOUR_ZONE_HOSTNAME.
Replace YOUR_ZONE_HOSTNAME with the hostname the provider assigned to your zone. Why a subdomain: RFC 1034 forbids a CNAME at the zone apex, so serving assets from example.com itself needs provider-specific ALIAS or CNAME flattening. A dedicated asset hostname also makes rollback a one-record change.
Issue a certificate for the asset hostname through the provider, using DNS or HTTP validation. Require TLS 1.3 where clients allow it, and redirect plain HTTP to HTTPS at the edge. Add HSTS only after the first full day of clean traffic. Why: an HSTS mistake is cached in browsers for the full max-age and cannot be purged.
Map the classes from Step 1 to path rules. Prefer honoring origin Cache-Control and use edge overrides only where the origin cannot be changed.
| Asset type | Path pattern | Origin Cache-Control | Edge rule | Invalidation |
|---|---|---|---|---|
| Hashed JS, CSS, source maps | /static/hashed/* | public, max-age=31536000, immutable | Cache 1 year, ignore query strings | None: new build, new URL |
| Fonts | /fonts/* | public, max-age=31536000, immutable | Cache 1 year, pass Access-Control-Allow-Origin | Rename on change |
| Images, PDFs, marketing files | /images/* | public, max-age=86400, stale-while-revalidate=86400 | Cache 24 to 72 hours, optional WebP or AVIF | Path purge |
| Installers, archives | /downloads/* | public, max-age=604800 | Cache several days, allow range requests | Versioned filenames, prewarm releases |
| Avatars, runtime config | /u/*, /config/* | public, max-age=60 to 300, with ETag | Short TTL, revalidate | Let TTL expire |
Only the low-mutation row ever needs a routine purge, because immutable files change URL and high-mutation files expire within five minutes.
Change the asset base URL in the build config so HTML references static.example.com. Add a preconnect resource hint for the asset hostname in the document head so the browser opens the TLS connection early. The trade-off: a path-based setup (example.com/static routed to the CDN) avoids the extra connection but couples CDN routing to application routing, which makes rollback harder.
Pull caching fits normal web assets: the first request per edge fills the cache. For large release artifacts that must be hot at launch, such as a 4 GB installer, push or prewarm through the provider API before you publish the link. Enable HTTP/3 if your provider supports it; most clients fall back to HTTP/2 cleanly when it is absent.
Validate from at least two regions before you announce the change. Use any HTTP client that shows response headers (browser developer tools, a command-line client, or a synthetic monitor) and check each item below:
If all seven pass, edge TTFB on cached objects should drop well below origin TTFB from distant regions. Record both, because that delta is your before-and-after evidence.
A reasonable target is above 95% cache hit ratio for immutable assets and above 90% overall. Track it per path prefix, not as one global number, because a healthy hashed bundle can hide a broken image path. Pair it with origin offload (bytes served from cache divided by total bytes), edge error rate, and edge TTFB.
A worked example shows why a few points matter. At 40 TB of static egress a month, a 90% byte hit ratio leaves 4 TB coming from origin; at 97%, origin serves 1.2 TB. That 2.8 TB difference, at an assumed cloud egress rate of $0.05 to $0.09 per GB (our estimate, check your own bill), is $140 to $252 a month. Miss-driven origin requests also fall by 70%, from 10% of traffic to 3%, which matters more during a launch spike than the dollars do.
Rehearse this on staging before production. A rollback that has never run is a hypothesis.
Purge by path or by cache tag, never purge-all as a habit. A full purge empties every edge at once and sends the whole working set back to origin in minutes, a refill surge that can exceed the origin's normal load several times over. With fingerprinted URLs, routine deploys need no purge at all.
Most failures in CDN for static file delivery come from four causes: query strings that fragment the cache, a Vary header that varies on the wrong thing, origin headers that forbid caching, and missing CORS on fonts. Each one shows a distinct symptom in the headers, so diagnose from the response before changing provider settings.
Plan for 60 to 90 minutes of configuration plus one DNS TTL for cutover. Most of the time goes into origin headers and cache rules, not the CNAME. Lowering the DNS TTL to 300 seconds a day earlier keeps cutover and rollback to roughly five minutes, and a staging rehearsal adds another hour that is worth spending.
A dedicated subdomain such as static.example.com is usually the better choice for static files on a CDN. It isolates cache rules, avoids cookies on asset requests, and makes rollback a single DNS change. A path on the main domain saves one connection, but it couples CDN routing to application routing and complicates troubleshooting.
Hashed static files should use Cache-Control: public, max-age=31536000, immutable. The one-year max-age keeps them at the edge and in browsers, and immutable tells browsers to skip revalidation on reload. This is safe only when the filename changes whenever the content changes, which is what content hashing in the build pipeline guarantees.
No, a CDN for static files does not need a purge on every deploy if filenames are fingerprinted. New builds reference new URLs, and old objects simply age out. Purges are needed only for files overwritten in place, such as marketing images, and those should be purged by exact path or tag, not with a purge-all.
A low CDN cache hit ratio for static files usually comes from query-string variations, a Vary header on Cookie or User-Agent, or origin responses marked private or no-store. Break the ratio down by path prefix to find the offender, then inspect its response headers. Low-traffic long-tail files also miss more often, which origin shield helps reduce.
Export 24 hours of CDN logs and group them by path prefix. For each prefix, compute byte hit ratio, count distinct query strings per object, and list the Cache-Control and Vary values the origin returned. Any immutable prefix under 95%, or any object with more than a handful of query-string variants, is a rule to fix today. Then rehearse the rollback runbook on staging and time it. That audit pays off on any provider, including the one you run now.
If you are choosing a provider for high-volume static files, the BlazingCDN features for static file delivery page lists what every plan includes, from origin shield and request coalescing to purge, cache warm-up through the API, and Prometheus metrics.