Skip to content

worker-tools/workers.js.org

Repository files navigation

layout logo description buttons
landing
<picture> <source srcset="assets/img/logo_d.svg" media="(prefers-color-scheme: dark)"> <img src="assets/img/logo_l.svg" alt="Logo" width="172" height="172"> </picture>
Worker Runtimes are the **new standard** for writing **HTTP servers** in JavaScript.
[Learn More](#state-of-worker-runtimes){:.btn.btn-primary} [Contribute](#contributing){:.btn.btn-default style="font-weight:normal"}

Worker Runtimes

  • Table of Contents {:toc .large-only}

Origin

Worker Runtimes are an adaptation of the Service Workers API, which is a browser standard for offline web applications. To give web developers more freedom over offline experiences, the specification includes a (minimal) HTTP server. Since it was published, other vendors have implemented this API for servers that run in the cloud — or on the edge in the case of Cloudflare Workers.

Typically, they also implement other browser APIs such as Fetch, Streams, and Web Cryptography, making their global scope similar to that of a Service Worker. We call them Worker Runtimes or Worker Contexts.

To see which vendors and APIs are available, check out the State of Worker Runtimes{:.heading} below.

self.addEventListener('fetch', event => {
  event.respondWith(new Response('Hello World', {
    headers: { 'Content-Type': 'text/plain' }
  }));
})

{:.larger}

Example of a minimal HTTP server using Service Workers API {:.figcaption style="margin-top:-1rem"}

Since originally writing this, both Deno and Cloudflare Workers have dropped support for the pattern shown above. While the Request and Response classes remain, the global fetch event and respondWith method do not. The reasons are difficult to ascertain, but it seems it was deemed too confusing for beginners. {:.note title="Deprecation Notice"}

State of Worker Runtimes

Last modified at: {{ page.last_modified_at | date:"%b %d %Y" }} {:.heading.post-date}

There are currently two production quality Worker Runtimes. There are multiple offline, testing, and development implementations. Cloudflare Workers was the first, and is the most battle-tested Worker Environment. Deno Deploy is a close second. {:.note title="Summary"}

Cloudflare Workers{:style="max-width:22.5rem;margin-top: 1rem"}{:.no-mark title="Cloudflare Workers"} Deno Deploy{:style="max-height:6.5rem;margin:.75rem"}{:.no-mark title="Deno Deploy"} Miniflare{:style="max-height:6.5rem;margin-top:.75rem"}{:.no-mark title="Miniflare"}


{:.clearfix}


| | Service Workers | Cloudflare Workers | Deno CLI | Deno Deploy | Fastly Compute@Edge | Miniflare | cfworker/dev | cloudflare-
worker-local
| |:------------------------|:-:|:-:|:-:|:-:|:-:|:-:|:-:| | Domain | Client | Edge | Server | Edge | Edge | Testing, Dev | Testing, Dev | Testing, Dev | | Open Source | ✅ | ✅ | ✅ | ℹ️ | ✅ | ✅ | ✅ | ✅ | | 1.0 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |

Legend

✅ : Supported

ℹ️ : Partial support / attention required

🔜 : Implementation in progress

👨‍💻 : Supported via 3rd party library / polyfill

❓ : Support to be determined

🚫 : Not supported

🔙 : Backwards compatibility only

💀 : Support dropped {:.legend}

Browser APIs

The center piece of any Worker Environment is an implementation of the global fetch event. Implementations of other browser APIs are necessary for bridging the gap between different worker runtimes.

Service Workers Cloudflare Workers Deno CLI Deno Deploy Fastly C@E Miniflare cfworker/dev cloudflare-
worker-local
fetch event 🔙 👨‍💻 🚫
URL API ℹ️
Fetch API
Abort Controller/Signal 👨‍💻 👨‍💻
URL Pattern API ℹ️ 🚫 👨‍💻 👨‍💻
Encoding API
Streams API ℹ️ ℹ️ ℹ️ ℹ️ 🚫
Encoding Streams ℹ️ 🚫 🚫 🚫 🚫 🚫
Compression Streams ℹ️ 🚫 🚫 🚫
Web Cryptography API ℹ️
crypto.randomUUID() ℹ️ 🚫
Cache API ℹ️ 🔜 🚫 ℹ️ ℹ️
WebSocket API ℹ️ 🚫 ℹ️ 🚫 🚫
Web Socket Stream 🔜 🔜 🚫 🚫 🚫
Location API 👨‍💻 🚫 👨‍💻 👨‍💻 👨‍💻
console ℹ️
queueMicrotask ℹ️
structuredClone ℹ️
navigator.userAgent 🚫
Response.json ℹ️ 🚫
EventTarget and Event
Web Workers API 🚫 🚫 🚫 🚫
Message Channel 🚫 🚫 🚫 🚫 🚫
Broadcast Channel ℹ️ 🚫 🔜 ℹ️ 🚫 🚫 🚫 🚫
IndexedDB 🚫 🚫 🚫 🚫 🚫
Performance API 🚫 🚫 🚫
{:.sticky-table}

Working Drafts

The APIs below are either abandoned or do not have buy-in from major browser vendors. However, they can still be reasonable targets for 3rd party libraries, such as KV stores or cookie middleware.

Service Workers Cloudflare Workers Deno CLI Deno Deploy Fastly C@E Miniflare cfworker/dev cloudflare-
worker-local
KV Storage API 👨‍💻 👨‍💻 👨‍💻 👨‍💻 🚫 👨‍💻 👨‍💻 👨‍💻
Cookie Store API ℹ️ 👨‍💻 👨‍💻 👨‍💻 👨‍💻 👨‍💻 👨‍💻 👨‍💻

Non-Standard APIs

These are useful APIs provided by one or more Worker Environment that aren't on any standards track (including abandoned).

Service Workers Cloudflare Workers Deno CLI Deno Deploy Fastly C@E Miniflare cfworker/dev cloudflare-
worker-local
scheduled event 🚫 🚫 🚫 🚫 🚫 🚫
HTMLRewriter 👨‍💻 👨‍💻 👨‍💻 🚫 ℹ️ 👨‍💻
KV 🚫 🚫 🚫 🚫 ℹ️
Durable Objects 🚫 🚫 🚫 🚫 🚫 🚫
crypto.DigestStream 🚫 🚫 🚫 🚫 🚫 🚫
Ed25519 via WebCrypto 🚫 🚫 🚫 🚫 🚫 🚫

General Capabilities, Non-Standard

These are some general capabilities provided by one or more Worker Environment that share similarities but aren't tied to a specific API.

Service Workers Cloudflare Workers Deno CLI Deno Deploy Fastly C@E Miniflare cfworker/dev cloudflare-
worker-local
File system access 🚫 🚫 ℹ️ 🚫 🚫 🚫 🚫
Connect TCP 🚫 🔜 🚫 🔜 🚫 🚫
Connect UDP 🚫 🔜 🔜 🔜 🚫 🔜 🚫 🚫
WebSockets (Server) 🚫 🚫 🚫 🚫

Backend for Frontend

Worker Runtimes fulfill the original promise of NodeJS: To use one language and share code between client and server. In practice, this never came to be. Instead the APIs of node and browsers have diverged1. Worker Runtimes are bringing them back together.

This is good news for Frontend Developers in particular: The knowledge acquired for building (offline) web applications can now be applied to writing HTTP servers --- and so can the tools:

Worker Tools Logo{:width="120" height="120"}{:.no-mark} {:.centered style="margin:3rem auto -3rem"}

Tools

No HTTP Server is complete without a web framework for common tasks such as routing, sessions, authentication, and more.

Worker Tools is a collection of tools and libraries for writing web servers, built specifically for Worker Runtimes. They can be used independently, or as a complete framework via Shed.

Contributing

Are you aware of any other Worker Runtimes available or in development? Did you find any inaccuracies in the tables above? Open a PR in the workers.js.org repository!


<style> dl.legend { display: grid; grid-template-columns: repeat(auto-fill, 36px minmax(min(300px, 100%), 1fr)); grid-gap: 0.5rem; }

dl.legend dd { margin: 0; } table th:first-of-type { width: 220px; } table th:not(:first-of-type) { width: 180px; } table a::after { content: none!important; } </style>

Footnotes

  1. Node and the browser have diverged due to a lack of browser APIs for many crucial components, including HTTP, streams, file access, and more more. A lot has changed since then. Standards have been written for all of these and more, often informed by the experience of using the node-equivalent.

About

Worker Environments are the new standard for authoring HTTP servers in JavaScript.

Resources

Stars

Watchers

Forks