Skip to content

Exclude files from the CDN

Keep files that change often out of the CDN by path, by page URL, or by file type. How the three kinds work, what it costs, and the one limit of the URL kind.

Static files (images, CSS, JavaScript, fonts, downloads) are served from Cloudflare's locations close to your visitors. A file you replace under the same name can show its old version until the CDN cache expires. Exclude those files, and the CDN keeps no copy: every request reaches your site, so visitors get the newest file.

Excluding files increases your resource usage, because your server answers each request itself. Exclude as little as you can.

Open your site, then Caching, then the CDN tab, and press Settings on the Exclude files from CDN card. The page has three cards. Each change runs as a job, and the CDN tab says what the server holds.

Exclude files or folders

Type a path from the web root, such as /wp-content/uploads/ or /wp-content/themes/mytheme/app.js, and press Add path. A folder is excluded with all the folders under it. Paths are matched without regard to case. A path can use letters, digits, and . _ ~ @ + -, so it cannot leave the web root, and the web root itself is not allowed (it would exclude every file). You can add up to 50 paths.

Exclude on URL

When a page loads, its images and CSS files are asked for with a Referer header that names the page. Add /blog/ and every file that a page under /blog/ asks for is excluded. You can type a path, or paste a full address on one of your site's own hostnames. The query string is ignored. / means the home page alone. You can add up to 50 URLs.

The limit of this kind: it acts on a request that reaches your server. If another page already put a file in the CDN cache, a page that is excluded can still get that copy until it is cleared. To keep a file out everywhere, exclude it by path or by file type. Changing the list clears your site's files at the CDN, so you start without copies.

Exclude file types

Pick an extension from the list and press Add extension. The list holds the types Cloudflare caches by default (css, js, png, jpg, woff2, pdf, zip, and others). All files with that extension are excluded.

What an excluded file does

The server answers with Cloudflare-CDN-Cache-Control: no-store, which Cloudflare reads and does not pass on, and Cache-Control: no-cache, so the browser asks again each time (and gets a quick "not modified" when nothing changed). To check:

curl -sI https://example.com/wp-content/uploads/private/report.pdf

The answer has cache-control: no-cache and no cf-cache-status: HIT.

Pages are not files

Pages have their own list: Paths the cache skips on the Rules tab. Exclusions here apply to files with an extension (not .php, .html, or .htm).

Still stuck?

Email support at wpwaterfall dot com with your site name and what you tried, or send us a message.