Github iconEdit on Github
This version of the Cloudflare Workers documentation is deprecated. Visit the new documentation

Writing Workers

Get Started in the Playground

The Worker Playground makes it easy to experiment with Workers. Workers you create in the playground can be tested against any site.

Launch Playground

Workers created in the Playground are only for experimentation and don’t run on all of Cloudflare’s infrastructure around the world. To enable that, write a Worker inside your Cloudflare configuration dashboard.

Write a Real Worker

Once you’re ready to write a production Worker, move into the development environment inside the Cloudflare dashboard.

The site which you would like to develop a Worker on should be set up with Cloudflare. If not, sign up now and update your DNS.

Begin by logging in to your Cloudflare dashboard.

Navigate to the 'Workers' tab: Workers Tab

Click the 'Launch Editor' button. It will open the Workers code editor: Launch Workers

You will see a default Worker script. This script, when deployed does a simple pass-through and does not change any behavior on your site: Default Script

Replace the pre-filled script with the following snippet of code and save it:

addEventListener('fetch', event => {

async function fetchAndApply(request) {
  return new Response('hello world')

This script, instead of loading from your origin, returns a response directly from our edge.

To enable this Worker on your site, go to the 'Routes' pane: Routes Tab

If your domain is ‘’, create a route that says and hit ‘Save’. Replace ‘’ in this example with your actual domain: Create a Route

Visit on your browser. You will see your Worker returning the response: Visit Link

Check out our recipes to see what other cool things you can do with Workers.