Understanding Cloudflare's CDN

Learn about the Cloudflare Content Delivery Network (CDN), how it operates, what content it caches by default, and how to customize your caching.


Overview

Cloudflare’s Content Delivery Network (CDN) is a geographically distributed group of servers that ensure fast delivery of Internet content including HTML pages, JavaScript files, stylesheets, and images. Caching static resources at Cloudflare reduces your server load and bandwidth, with no extra charges for bandwidth spikes.

Cloudflare does not require an extra CDN subdomain or hostname and you do not need to change your URLs.

There are many reasons to use Cloudflare’s CDN for your site:

User Experience: Without Cloudflare’s CDN, visitors geographically distant from your origin web server experience slow page loads. Cloudflare’s Anycast network brings content geographically closer to your visitors to reduce page load and latency.

Traffic surges: Due to a major news release or online event, sudden influxes of traffic to your site can overload your origin web server. Cloudflare’s CDN serves your cached content to remove load from your origin web server.

DDoS ProtectionDistributed Denial of Service (DDoS) attacks disrupt websites by flooding their infrastructure with traffic. Cloudflare’s CDN has a network capacity 15 times bigger than the largest DDoS attack ever recorded and handles modern DDoS to ensure your website stays online.


Understand Cloudflare's default cache behavior

Cloudflare caches static content depending on:

  • where your visitors come from,
  • which Cloudflare data center your visitors reach, and
  • how often visitors request a resource at the specific data center.

Cloudflare only caches a resource within the Cloudflare data center that serves the request and doesn’t cache:

  • off-site or third-party resources (Facebook, Flickr, etc), or
  • content hosted on unproxied (grey-clouded) DNS records.

By default, Cloudflare respects the origin web server’s cache headers in the following manner unless overridden via an Edge Cache TTL Page Rule:

  • If the Cache-Control header is set to private, no-store, no-cache, or max-age=0, or if there is a cookie in the response, then Cloudflare does not cache the resource.
  • Otherwise, if Cache-Control is set to public and the max-age is greater than 0, or if the Expires header is a date in the future, Cloudflare caches the resource.
  • If both max-age and an Expires header are set, max-age is used.

By default, Cloudflare caches certain HTTP response codes with the following Edge Cache TTL:

200, 206, and 301   120 minutes
302 and 303             20 minutes
403                              1 minutes
404                              3 minutes
410                               3 minutes

Cloudflare’s CDN provides several cache customization options:

  • Specify caching behavior for individual URLs via Cloudflare Page Rules
  • Customize caching with Cloudflare Workers
  • Adjust caching level, cache TTL, and more via the Cloudflare Caching app
The maximum file size Cloudflare's CDN caches is 512MB for Free, Pro, and Business customers and 5GB for Enterprise customers. Enterprise customers can contact their Cloudflare Account Team to request caching of larger files.

Cloudflare limits upload size (HTTP POST request size) per plan type:

If you require larger uploads, either:

  • chunk requests smaller than the upload thresholds, or
  • upload the full resource through a grey-clouded DNS record.

Understand file extensions cached by default

Cloudflare only caches based on file extension and doesn’t cache by MIME type. The Cloudflare CDN automatically caches files containing certain file extensions and doesn’t cache HTML by default:

bmp

ejs

jpeg

pdf

ps

ttf

class

eot

jpg

pict

svg

webp

css

eps

js

pls

svgz

woff

csv

gif

mid

png

swf

woff2

doc

ico

midi

ppt

tif

xls

docx

jar

otf

pptx

tiff

xlsx

Cloudflare also caches a website's robots.txt.  Cache additional content by creating a Cloudflare Page Rule to Cache Everything.


Understand Cloudflare cache responses

The output of the CF-Cache-Status header shows whether a resource is cached:

HIT

The resource was found in Cloudflare’s cache.

MISS

The resource was not found in Cloudflare’s cache and was served from the origin web server.

EXPIRED

The resource was found in cache but has since expired and was served from the origin web server.

STALE

The resource was served from cache but is expired. Cloudflare couldn’t contact the origin to retrieve the updated resource.

BYPASS

The origin server instructed Cloudflare to bypass cache via a Cache-Control header set to no-cache, private, or max-age=0. BYPASS is returned when enabling Origin Cache-Control.

REVALIDATED

The resource is served from cache but is stale. The resource was revalidated by either an If-Modified-Since header or an If-None-Match header.

UPDATING

The resource was served from cache but is expired. The resource is currently being updated by the origin web server. UPDATING is typically seen only for very popular cached resources.

DYNAMIC

The resource content type was not cached by default and your current Cloudflare caching configuration doesn't instruct Cloudflare to cache the resource.  Instead, the resource was requested from the origin web server. Use Page Rules to implement custom caching options.

Use a service like Redbot or webpagetest.org to investigate cache responses returned by the CF-Cache-Status header.  Alternatively, investigate via a visual tool such as Chrome's Dr. Flare plugin.

Related resources

Not finding what you need?

95% of questions can be answered using the search tool. This is the quickest way to get a response.

Powered by Zendesk