You push your static assets to a CDN, refresh your production site, and your clean typography falls back to default system Arial or Times New Roman. Pop open DevTools, and there’s that familiar red wall of text: Access to font at 'https://cdn.example.com/fonts/inter.woff2' from origin 'https://example.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Browsers treat web fonts (.woff, .woff2, .ttf, .eot) and assets requested via fetch or canvas as cross-origin by default. If your CDN edge doesn’t send the right response headers, the browser simply refuses to parse the font file. I hit this exact issue while setting up edge delivery on StackPath, and fixing it requires configuring both your origin server and your edge caching behavior so they actually work together.

Why CDNs Break Web Fonts with CORS
Under the browser’s Same-Origin Policy, web fonts are blocked across domains unless the server explicitly allows sharing. When a page on https://example.com requests a font living at https://cdn.example.com, the browser sends an Origin: https://example.com request header. The MDN CORS documentation breaks down the exact handshake if you want the underlying spec.
The browser expects the CDN to hand back an Access-Control-Allow-Origin header that matches the site origin or uses *.
Three common snags trigger this error:
- Your origin server never sent the CORS header: StackPath passes origin headers through by default. If your Nginx or Apache config omits them, the CDN has nothing to forward.
- The CDN cached a request that lacked CORS headers: If a crawler, health check, or direct browser tab hit
https://cdn.example.com/fonts/inter.woff2without anOriginheader, your origin returned a naked 200 OK without CORS headers. StackPath cached that naked response and started serving it to cross-origin browsers. - Missing Vary header: Without
Vary: Origin, edge caches treat requests from different origins identically, serving the wrong cached header set to subsequent visitors.
If you’ve followed our walkthrough to deploy Vite React SPA on Hostinger with Namecheap and StackPath, you already know that keeping assets on a separate CDN subdomain keeps things fast—as long as your response headers don’t get in the way.
Testing Missing Headers with cURL
Before you start rewriting web server configs, check what StackPath’s edge is actually returning right now. Don’t rely on your browser; local disk caches and service workers will lie to you.
Fire a HEAD request via curl, explicitly passing an Origin header to mimic Chrome or Firefox:
curl -I -H "Origin: https://example.com" https://cdn.example.com/fonts/inter-bold.woff2Inspect the output. If it looks like this, your CORS setup is broken:
HTTP/2 200
server: StackPath
date: Wed, 18 Oct 2023 14:22:10 GMT
content-type: font/woff2
content-length: 34212
cache-control: public, max-age=31536000
x-cache: HIT Notice what’s missing? Zero sign of an access-control-allow-origin header. Even though the CDN gave you an HTTP 200 OK, the browser drops the font glyphs right there.
Next, test your origin server directly (bypassing StackPath entirely) to see if the origin is failing to emit the header:
curl -I -H "Origin: https://example.com" https://origin.example.com/fonts/inter-bold.woff2If the origin leaves out the header too, you need to fix your origin config first.
Fix 1: Configure CORS Headers on Your Origin Server
The cleanest setup is having your origin web server emit proper CORS headers on static fonts. Once the origin provides them, StackPath caches them at the edge and serves them to every downstream client.
For Nginx Origins
Open your Nginx site configuration (usually in /etc/nginx/sites-available/example.com or inside your main server block) and set these headers inside your static asset location block:
location ~* .(eot|ttf|woff|woff2|svg)$ { add_header Access-Control-Allow-Origin "*" always; add_header Access-Control-Allow-Methods "GET, OPTIONS" always; add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept" always; add_header Vary "Origin" always; expires 365d; access_log off; add_header Cache-Control "public, max-age=31536000, immutable";
} The always directive is critical here. It forces Nginx to send the CORS header even on 4xx or 5xx error responses, preventing misleading CORS errors from masking underlying file permission or routing bugs.
If you’ve already locked down your server using our guide to restrict origin server access to StackPath Origin Shield IPs in Nginx, ensure these add_header lines live inside that active protected server block.
Test the syntax and reload Nginx:
sudo nginx -t
sudo systemctl reload nginxFor Apache Origins (.htaccess)
On Apache or standard cPanel shared hosting, confirm mod_headers is enabled, then add this block to your root .htaccess file:
Header set Access-Control-Allow-Origin "*" Header set Access-Control-Allow-Methods "GET, OPTIONS" Header append Vary "Origin"
Using Header set overwrites duplicate headers, while Header append Vary "Origin" tells downstream caches that responses differ based on the request origin.
Fix 2: Inject CORS Headers Using StackPath EdgeRules
What if you don’t control the origin server? Or what if your assets sit in an AWS S3 bucket or Google Cloud Storage container where configuring custom headers per file extension is tedious? You can use StackPath EdgeRules to inject the CORS headers directly at the CDN POPs before sending responses back to the browser.
Here’s how to configure it in the portal:
- Log in to your StackPath dashboard and go to CDN > Sites.
- Select your target site and click the EdgeRules tab.
- Click Add EdgeRule in the top right.
- Name it something descriptive, like
Inject CORS for Static Fonts.
Under If (Conditions), target font extensions:
- Condition:
URL Path>Matches Regex - Value:
.(woff|woff2|ttf|otf|eot|svg)$
Under Then (Actions), add the headers:
- Action 1:
Add Response Header - Header Name:
Access-Control-Allow-Origin - Header Value:
*
Add a second action to keep caches segregated properly:
- Action 2:
Add Response Header - Header Name:
Vary - Header Value:
Origin
Click Save EdgeRule. StackPath edge nodes push EdgeRule updates globally within 60 to 90 seconds.
Preventing Cache Poisoning with the Vary Header
A classic edge bug happens when fonts load fine on initial test, but break for the next visitor. This stems from an edge cache ignoring the HTTP Vary header. The MDN documentation on Vary explains the mechanics in detail.
Here’s how this plays out in practice:
- Someone hits your staging domain
https://staging.example.com, requestinghttps://cdn.example.com/fonts/font.woff2. - The origin sees
Origin: https://staging.example.comand responds withAccess-Control-Allow-Origin: https://staging.example.com. - StackPath caches that response object against the font’s URL.
- A real user hits your production site
https://example.com. StackPath serves the cached response withAccess-Control-Allow-Origin: https://staging.example.com. - The browser detects the origin mismatch and blocks the font cold.
To avoid this, either use a wildcard * for public static assets or ensure your origin sends Vary: Origin so the CDN stores unique cache entries per requesting origin.
For high-traffic infrastructure with multi-tier caching, check out our guide on how to prevent CDN cache stampedes with Origin Shield and Stale-While-Revalidate to maintain stable edge behavior under load.
Purging the CDN Cache After Updates
Fixing Nginx, Apache, or EdgeRules won’t fix live browser errors if StackPath already has a poisoned, headerless version of your font stored in its cache. You have to purge it.
Purging via the StackPath dashboard:
- Navigate to CDN > Sites > your site.
- Click the Purge tab.
- Select Purge by URL and supply the path pattern:
/fonts/*(or specify exact file URLs). - Click Submit Purge.
If you’re automating deployments, purge programmatically via the StackPath API with curl:
curl -X POST https://gateway.stackpath.com/cdn/v1/stacks/{stack_id}/sites/{site_id}/purge -H "Authorization: Bearer YOUR_API_TOKEN" -H "Content-Type: application/json" -d '{ "items": [ {"url": "https://cdn.example.com/fonts/inter-bold.woff2", "recursive": false} ] }'StackPath edge purges generally propagate across all POPs in under 500ms.
Verifying the Solution in the Terminal
Once purged, test the edge URL again with an explicit Origin header:
curl -I -H "Origin: https://example.com" https://cdn.example.com/fonts/inter-bold.woff2Check the response headers carefully:
HTTP/2 200
server: StackPath
date: Wed, 18 Oct 2023 14:48:02 GMT
content-type: font/woff2
content-length: 34212
access-control-allow-origin: *
access-control-allow-methods: GET, OPTIONS
vary: Origin
cache-control: public, max-age=31536000, immutable
x-cache: MISSRun the exact same curl command a second time:
curl -I -H "Origin: https://example.com" https://cdn.example.com/fonts/inter-bold.woff2 The x-cache header should now report HIT, while access-control-allow-origin: * stays firmly intact. Open an incognito browser window, reload your site, and confirm the typography loads without errors in DevTools.
Gotcha: Preflight OPTIONS Requests on Asset CDNs
CSS @font-face declarations trigger simple GET requests. But if your frontend uses fetch() to load 3D assets (like .gltf or .bin files) or custom canvas graphics, the browser sends an HTTP preflight OPTIONS request first.
By default, many origin servers reject OPTIONS requests on static assets, returning 405 Method Not Allowed. If your CDN returns a 405 on an OPTIONS preflight, the browser terminates the request before the GET call ever happens.
In Nginx, catch OPTIONS requests on static assets and return a fast 204 No Content directly:
location ~* .(eot|ttf|woff|woff2|svg|gltf|bin)$ { add_header Access-Control-Allow-Origin "*" always; add_header Access-Control-Allow-Methods "GET, OPTIONS" always; add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept, Authorization" always; if ($request_method = 'OPTIONS') { add_header Access-Control-Allow-Origin "*" always; add_header Access-Control-Allow-Methods "GET, OPTIONS" always; add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept, Authorization" always; add_header Access-Control-Max-Age 86400; add_header Content-Length 0; add_header Content-Type text/plain; return 204; } expires 365d; add_header Cache-Control "public, max-age=31536000, immutable";
}The Access-Control-Max-Age 86400 header tells the browser to cache that preflight decision for 24 hours, cutting out redundant round-trips.
Edge Architecture: Keeping Origins Secure
While tweaking CORS headers and edge passthroughs, make sure your origin isn’t exposed directly to arbitrary internet traffic. Bypassing the CDN leaves your backend wide open to direct scrapers and unexpected load.
Pairing CORS fixes with an Origin Shield setup gives you both clean header delivery and robust origin isolation. See our walkthrough to configure Origin Shield in StackPath CDN for traffic spikes to keep your backend safe while serving assets globally.
Frequently Asked Questions
Can I use my site URL instead of an asterisk for Access-Control-Allow-Origin?
Yes. If you want to stop other sites from hotlinking your fonts, set Access-Control-Allow-Origin "https://example.com" instead of *. Just be sure to include Vary: Origin so your CDN edge caches separate versions for different referrers.
Why does my font work on initial load but fail on hard refresh?
This is almost always a cache poisoning issue. An asset requested without an Origin header (like opening the font URL directly in a tab) gets cached locally or at the edge without CORS headers, then reused by your stylesheet. Setting Vary: Origin and clearing your local cache resolves it.
Do I need CORS headers for CSS and JS files?
Standard and tags do not require CORS headers. But if you load scripts using ES modules () or read stylesheet rules via the CSSOM or canvas, CORS headers are required.
Why is StackPath returning a 403 Forbidden after I edited EdgeRules?
Check the regex in your EdgeRule condition. A broken regular expression or conflicting WAF rule will trigger an immediate 403. Check rule precedence in the EdgeRules UI to make sure an earlier rule isn’t blocking requests before your header rule executes.
With your fonts serving proper headers, keep an eye on cache behavior under real traffic. Read our guide on preventing CDN cache stampedes with Origin Shield and Stale-While-Revalidate to make sure your edge layer holds up when traffic surges.

