Getting Started with Cloudflare Workers
Cloudflare Workers let you run code on a global network of data centers, close to your users. Instead of routing requests to a single origin server, your script runs at the edge.
Why the edge?
Latency is a feature. When your code runs near the user, pages load faster and APIs respond sooner. Workers run in hundreds of Cloudflare locations worldwide.
Your first worker
A Workers script is just an ES module exporting a fetch handler:
export default {
async fetch(request) {
return new Response("Hello World!");
},
};Deploy it with wrangler deploy and you get a URL on workers.dev immediately.
What to build next
- A proxy that rewrites headers or caches responses
- An API gateway routing to multiple backends
- A full site rendering HTML at the edge, like this one
The best way to learn is to ship something small and iterate.