
The page works on your laptop. Then the static files move to a CDN hostname, and the text turns into a default system font. The console blames something called CORS. One response header usually settles it: Access-Control-Allow-Origin.
Why do fonts break when they move to a CDN hostname?
Browsers treat www.bakery.example and cdn.bakery.example as different origins. Wikipedia's article on cross-origin resource sharing (CORS) explains the background: a page may freely embed cross-origin images, stylesheets, scripts and videos, but some requests are forbidden by default under the same-origin policy, and CORS defines how the browser and server agree that a request is safe.
Fonts are one of those cases in practice. NetDNA's support article on webfonts says it directly: when a font loaded through @font-face comes from a third-party URL, browsers such as Firefox and Internet Explorer refuse to use it, and the fix is a header in the server configuration. A bakery in Manchester that moved serif.woff2 to cdn.bakery.example would see exactly this: a 200 response, a visible file in the network tab, and no font on the page.
One detail trips people up. Per Wikipedia, the header is set by the server that serves the resource, not by the page that asks for it. So www.bakery.example can't grant itself access; cdn.bakery.example has to say yes.
When is a wildcard safe?
A wildcard looks alarming, so teams avoid it and write long allow-lists they then forget to maintain. For a public font, the allow-list buys nothing.
Wikipedia describes the value * as appropriate when a response is meant to be readable by code on any site, and gives a freely available web font on a public hosting service as its example. It also notes that the wildcard doesn't allow credentials: cookies, HTTP authentication and client certificates aren't sent with such requests. A public font file carries no secrets, so the wildcard exposes nothing the URL didn't already expose.
For Apache, NetDNA's article uses a short block in .htaccess. The Nginx equivalent is:
location ~* \.(woff2?|ttf|otf|eot)$ {
add_header Access-Control-Allow-Origin "*";
add_header Cache-Control "public, max-age=31536000, immutable";
}
The one-year lifetime is safe for fingerprinted font files, and a long lifetime on files that never change helps your cache hit ratio.
What if only your own sites should read the file?
Some responses shouldn't be public: a JSON feed that powers a storefront, say. Say cdn.shop.example serves /prices.json and only https://shop.example should read it from JavaScript. The server then replies with that specific origin:
Access-Control-Allow-Origin: https://shop.example
Vary: Origin
The Vary: Origin line matters because of caches. Without it, a shared cache could store the response made for one site and replay it, header included, to a request from another, and the second site would be blocked or, worse, wrongly allowed. With it, the cache keeps one copy per origin.
Wikipedia also warns about one combination. If a site sends Access-Control-Allow-Credentials: true, third-party sites may be able to carry out privileged actions and retrieve sensitive information. So an allow-list that echoes back whatever origin asks, plus credentials, is the setup to avoid. Matching against a fixed list, and returning a single value, is the safer pattern.
Non-simple requests add a step. For methods or headers outside the safe set, the browser first sends an OPTIONS preflight request and waits for the server's approval. Answering that with Access-Control-Allow-Methods and a sensible Access-Control-Max-Age lets the browser skip repeating it on each call.
How do you check the header the CDN really sends?
Editing the origin and reloading the page proves little, because the CDN may be serving an older copy. Test the edge directly, with a pretend origin:
curl -sI -H 'Origin: https://www.bakery.example' https://cdn.bakery.example/fonts/serif.woff2 | grep -i -E 'access-control|vary|cache-control'
Two things commonly go wrong. First, cached objects keep the headers they were stored with, so after a header change a purge of the affected files is needed before the edge reflects it. Second, error responses often lack the header. A missing font that returns 403 or 404 gets reported as a CORS failure, and the console message sends people looking in the wrong place. NetDNA's debugging article suggests checking for 403s and 404s first, which still applies.
Which header setup fits which file?
A short rule keeps this manageable: public static files (fonts, images, public scripts) get * with a long lifetime; data meant for named sites gets a matching origin plus Vary: Origin; anything that needs cookies gets neither a wildcard nor an echoed origin. Settle those three buckets once, and the next "the font disappeared" ticket takes a minute to diagnose.
Related: Working webfonts with CDN, custom expiry headers, mixed content on a CDN.
Blog