Skip to content

DispatchNamespaceScript

Source: src/Cloudflare/WorkersForPlatforms/DispatchNamespaceScript.ts

A user Worker uploaded into a Workers for Platforms dispatch namespace.

Dispatch namespace scripts are the per-customer Workers that a platform Worker invokes at runtime through a dispatch_namespace binding (env.DISPATCH.get(scriptName)). The upload API is a true upsert, so reconcile simply re-uploads the desired module; namespace and scriptName form the script’s identity and changing either triggers a replacement.

This resource supports small inline ES modules. For full bundling, assets, and rich binding support, see the follow-up notes in the Workers for Platforms catalog.

Inline user Worker

const namespace = yield* Cloudflare.DispatchNamespace("Customers", {});
const script = yield* Cloudflare.DispatchNamespaceScript("CustomerA", {
namespace: namespace.name,
script: `export default { fetch() { return new Response("hello"); } }`,
});

With compatibility date and customer tags

yield* Cloudflare.DispatchNamespaceScript("CustomerB", {
namespace: namespace.name,
scriptName: "customer-b",
script: `export default { fetch() { return new Response("hi"); } }`,
compatibilityDate: "2024-09-23",
tags: ["customer-b"],
});