Worker Runtimes are the new standard for writing HTTP servers in JavaScript.
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 below.
self.addEventListener('fetch', event => {
event.respondWith(new Response('Hello World', {
headers: { 'Content-Type': 'text/plain' }
}));
})
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.
State of Worker Runtimes
Last modified at: Oct 01 2022
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.
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
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 | ✅ | 🚫 | ✅ | ✅ | 🚫 | 🚫 | ❓ | ❓ |
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:
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!
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. ↩︎