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.
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 Protection: Distributed 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 when no `cache-control` directive or `expires` response header are present:
200, 206, 301 |
120m; |
302, 303 |
20m; |
404, 410 |
3m; |
403 |
1m; |
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
Cloudflare limits upload size (HTTP POST request size) per plan type:
- 100MB Free and Pro
- 200MB Business
- 500MB Enterprise by default (contact Customer Support to request a limit increase)
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:
avif |
bmp |
ejs |
jpeg |
|
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 even though Cloudflare originally preferred to cache the asset. BYPASS is returned when enabling Origin Cache-Control. Cloudflare also sets BYPASS when your origin web server sends cookies in the response header. |
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 |
Cloudflare does not consider the asset eligible to cache and your Cloudflare settings do not explicitly instruct Cloudflare to cache the asset. Instead, the asset was requested from the origin web server. Use Page Rules to implement custom caching options. |
When using Origin Cache Control and setting max-age=0, Cloudflare prefers to cache and revalidate. With Origin Cache Control off and max-age=0 Cloudflare settings bypass cache. Setting no-cache also bypasses cache.