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.

Cache content with Cloudflare

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),
  • content hosted on unproxied (grey-clouded) DNS records, or
  • content returned with no-cache, private, max-age=0 or outdated Expires headers from your origin web server.

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 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

Cache additional content by creating a Cloudflare Page Rule to Cache Everything.

Cloudflare caches both 301 and 302 redirects if there are no max-age=0, no-cache, private, or outdated Expires headers and if the URL is cacheable. 301 redirects are cached for a few hours and 302s are cached for less than 20 minutes.

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.

The CF-Cache-Status header is missing

If the CF-Cache-Status header is missing but you observe other Cloudflare headers such as CF-RAY, the resource was not cached. 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.

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