Proof-of-concept that offloads WordPress 7.0's real-time collaboration (RTC) to a Cloudflare Workers relay, replacing the default HTTP polling transport with WebSockets over Durable Objects.
WordPress 7.0 introduces collaborative editing powered by Yjs. By default it syncs via HTTP polling (every 1-4 seconds). This works, but each poll holds a PHP worker for the duration of the request. On hosts with limited concurrency, no WebSocket support, or stateless containers, this becomes a bottleneck.
This project moves the sync relay to Cloudflare's edge:
- Durable Objects coordinate document state with single-threaded consistency
- WebSocket Hibernation means idle editing sessions cost nothing
- PHP workers are freed from long-polling — they only handle normal page/API requests
Browser A ──WebSocket──┐
├── Cloudflare Durable Object (Yjs relay) ──persists to DO storage
Browser B ──WebSocket──┘
Four pieces work together:
| Component | Path | Purpose |
|---|---|---|
| Worker | worker/ |
Cloudflare Worker + Durable Object running y-partyserver as a Yjs sync relay |
| Plugin | plugin/wp-collab-cf/ |
WordPress plugin that hooks into the sync.providers filter to swap HTTP polling for a WebSocket connection to the Worker |
| MU-Plugin | mu-plugin/ |
Enables WP_ALLOW_COLLABORATION and sets the WP_COLLAB_CF_WS_URL constant that the plugin reads |
| Demo Plugin | plugin/wp-collab-cf-demo/ |
Optional. Magic link that creates temporary guest users restricted to a single demo post, useful for sharing a live demo |
cd worker
npm install
# Authenticate with Cloudflare (or set CLOUDFLARE_ACCOUNT_ID + CLOUDFLARE_API_TOKEN)
wrangler login
wrangler deployNote the deployed URL (e.g. wss://wp-collab-cloudflare.your-subdomain.workers.dev).
Copy the mu-plugin to wp-content/mu-plugins/ and set your Worker URL:
define( 'WP_COLLAB_CF_WS_URL', 'wss://wp-collab-cloudflare.your-subdomain.workers.dev' );cd plugin/wp-collab-cf
npm install
npm run buildCopy the plugin/wp-collab-cf/ directory (with the build/ output) into wp-content/plugins/ and activate it.
Open the same post in two browser tabs. Edits in one tab should appear in the other in real time.
The demo plugin provides a magic link for sharing a live demo publicly (e.g. on social media). When someone visits the link:
- A temporary guest user is created automatically (e.g. "Guest A3X9B2")
- They're logged in and redirected straight to the post editor
- All admin UI is hidden — they only see the block editor
- They can only edit the designated demo post, nothing else
- Copy
plugin/wp-collab-cf-demo/intowp-content/plugins/and activate it. - Create a post to use as the demo and note its ID.
- Set the post ID via WP-CLI or in wp-config:
define( 'WP_COLLAB_CF_DEMO_POST_ID', 123 );Or via option: wp option update wp_collab_cf_demo_post_id 123
- Share the magic link:
https://yoursite.com/?wp-collab-demo=1
-
The mu-plugin defines
WP_ALLOW_COLLABORATION(enabling RTC) andWP_COLLAB_CF_WS_URL(the relay endpoint). -
The plugin uses the
sync.providersfilter to replace WordPress's default HTTP polling provider with a WebSocket provider that connects to the Cloudflare Worker. It reuses WordPress's bundled Yjs instance (viawp.sync.Y) to avoid duplicate library issues. -
The Worker uses y-partyserver (built on PartyServer) to run a Yjs sync relay inside a Durable Object. Each post gets its own Durable Object instance, identified by a room name derived from the post type and ID. WebSocket Hibernation keeps idle rooms free.