Products ▾

Solutions ▾

Resources ▾

Developers

Pricing

Sign Up

Log In

Under Attack?

Cloudflare Workers

The Network is the Computer

Already a customer? Activate Today

"Moving away from VCL and adopting Cloudflare Workers will allow us to do some creative routing that will let us deliver JavaScript to npm's millions of users even faster than we do now. We will be building our next generation of services on Cloudflare's platform and we get to do it in JavaScript!"
CJ Silverio,
Chief Technology Officer at npm

Why go serverless?

"At Postmates, customer trust is the most important thing. We needed a way to do a high volume of redirects without dedicating additional internal resources. Cloudflare Workers gave us a simpler way to build flexibility and fine-grained control into our systems at the edge."

Aabhas Sharma,
Infrastructure Lead at Postmates

Building serverless applications with Cloudflare Workers

Cloudflare Workers lets developers deploy serverless JavaScript applications on Cloudflare's global cloud network, where they are seamlessly scalable and closer to end users. Built on top of the Service Workers API, Workers receive events for every HTTP(S) request made to an application. Workers then run application logic and can make subsequent requests to the Cloudflare Cache, Cloudflare Workers KV, or an application origin to return data to the user. The location of Workers on Cloudflare's global cloud network creates the following use cases for serverless:

Deliver personalized user experiences

Cache and modify lightweight static HTML pages while incorporating dynamic content based on user location, device type or time of day using the Cache API. Build responses from multiple background service requests either to the Cloudflare cache, application origin, or third party APIs.

Increase API responsiveness

Create a flexible API gateway to aggregate responses from multiple endpoints and return as a single response, eliminating the need for each endpoint to compile individual responses. Each request can also be split into multiple parallel requests then combined into a single response.

Implement custom application security

Build conditional responses for inbound requests that can assess and subsequently block or reroute malicious or unauthorized requests. Set parameters that can identify and authorize legitimate application traffic.

          
addEventListener('fetch', event => {
 event.respondWith(fetchAndApply(event.request))
})

async function fetchAndApply(request) {
 if (request.headers.get('user-agent')
 .includes('annoying_robot')) {
   return new Response
   ('Sorry, this page is not available.',
   { status: 403, statusText: 'Forbidden' })
  }
 return fetch(request)
}
          
        

Improve A/B testing performance

Enable randomized page selection by intercepting inbound HTTP(S) requests and serving content requests from the Cloudflare cache to specific control and test groups.

          
addEventListener('fetch', event => {
 event.respondWith(fetchAndApply(event.request))
})

async function fetchAndApply(request) {
 if (request.headers.get('cf-connecting-ip') === '225.0.0.1') {
  return new Response
  ('Sorry, this page is not available.',
  { status: 403, statusText: 'Forbidden' })
 }
 return fetch(request)
}
          
        

Get started quickly

Start with an extensive library of code snippets and recipes. Join the Cloudflare Workers community site to learn from other users.

Key Features

Cloudflare Workers saves us a great deal of time. Managing bot traffic without Workers would consume valuable development and server resources that are better spent elsewhere."

John Thompson,
Senior System Administrator at MaxMind

Everyone can start using Cloudflare Workers

Cloudflare protects and accelerates Internet applications and APIs. To start using Cloudflare Workers, you'll need a Cloudflare plan and an active Workers subscription.

Activate Today Already a customer?

Workers for Cloudflare's Free Plan

+ $5/Month

First 10M requests free;

$.50 per million thereafter


< 5ms CPU Processor Time


1 Script Included

Workers for Cloudflare's Pro Plan

+ $5/Month

First 10M requests free;

$.50 per million thereafter


< 10ms CPU Processor Time


1 Script Included

Workers for Cloudflare's Business Plan

+ $5/Month

First 10M requests free;

$.50 per million thereafter


< 50ms CPU Processor Time


1 Script Included

Workers for Cloudflare's Enterprise Plan

Custom

Custom Pricing


Negotiable CPU Processor Time


Unlimited Scripts Included