Skip to content

Cloudflare Basics

Use Cloudflare for CDN, DNS, edge functions, and security features for web applications.

What you'll learn

  • What Cloudflare provides and how it works
  • CDN and DNS management
  • Cloudflare Workers for edge computing
  • Security features: WAF, DDoS protection, SSL

Concept

What Is Cloudflare?

Cloudflare is a platform that sits between your visitors and your origin server, providing a content delivery network (CDN), DNS, security, and edge computing. When a visitor requests your site, Cloudflare serves cached content from the nearest edge location, reducing latency and origin load. Cloudflare has over 300 cities in its network, meaning content is delivered from close to the user wherever they are in the world.

CDN and DNS

Cloudflare's CDN caches your static assets — images, CSS, JavaScript — at edge locations worldwide. The first request fetches from your origin; subsequent requests are served from the cache, dramatically faster. Cloudflare can also manage your DNS, offering fast resolution and instant changes. Using Cloudflare for both DNS and CDN gives you a single control plane for your web infrastructure.

Cloudflare Workers

Workers are serverless functions that run at Cloudflare's edge — not in a single region, but in every city. You write JavaScript (or languages compiled to WebAssembly) and deploy it with Wrangler. Workers can modify requests, serve responses, run A/B tests, or build entire applications. Because they run at the edge, latency is minimal. CoderNewbie itself is deployed on Cloudflare Pages with Workers for dynamic functionality.

Security Features

Cloudflare provides a suite of security features. SSL/TLS is automatically provisioned and renewed — you get HTTPS with no effort. The Web Application Firewall (WAF) blocks malicious requests. DDoS protection is built in and always on. Bot management identifies and blocks automated traffic. Rate limiting protects against abuse. These features are configured through the dashboard or via API, and many are available on the free plan.

Cloudflare Pages

Cloudflare Pages is a static site hosting platform that integrates with Git. Push to your repository and Cloudflare builds and deploys automatically. It supports preview deployments for every pull request, custom domains, and automatic SSL. For dynamic functionality, Pages Functions run server-side code at the edge using the Workers runtime. This combination of static hosting with edge functions is powerful for Jamstack applications — you get the performance of static sites with the capability of server-side processing where needed.

Example

              # Install Wrangler CLI and authenticate
npm install -g wrangler
wrangler login

# Create and deploy a Cloudflare Worker
wrangler init my-worker
# src/index.ts:
#   export default {
#     async fetch(request: Request): Promise<Response> {
#       const url = new URL(request.url);
#       return new Response("Hello from " + url.hostname);
#     },
#   };
wrangler deploy

# Manage DNS records via the Cloudflare API
curl -X POST "https://api.cloudflare.com/client/v4/zones" \
  -H "Authorization: Bearer $CF_TOKEN" \
  -H "Content-Type: application/json"
            

Wrangler is the Cloudflare CLI for deploying Workers. Workers run at the edge in every city, giving minimal latency. The API can also manage DNS and other settings.

Try it

Common mistakes

The mistake

Not caching enough content at the edge

The fix

Set appropriate cache headers on static assets. Use Cloudflare's cache rules to cache aggressively. Uncached content hits your origin on every request, increasing latency and server load.

The mistake

Storing API tokens in client-side code

The fix

Use Cloudflare Workers secrets (wrangler secret put) for sensitive values. Never embed API tokens in client-side JavaScript — they are visible to anyone who opens the browser devtools.

Look up unfamiliar terms

A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.

View glossary

Build real projects

Apply what you learned by building guided projects with starter code and solutions.

View projects

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors