DEV Community

Cover image for I replaced ws with 2.5KB of code and deleted 14 dependencies
rabbxdev
rabbxdev

Posted on

I replaced ws with 2.5KB of code and deleted 14 dependencies

npm install ws = 1.2MB.

For a WebSocket.

I checked node_modules/ws and found 14 dependencies. To send {"type": "ping"}.

So I spent a weekend fixing it.

Meet @rabbx/ws: 2.5KB gzipped, zero dependencies

6.4KB minified. 2.5KB gzipped. 0 deps. Tree-shakeable. Side-effect free.

Same Web Standard API you know:

import { RbxSocket } from '@rabbx/ws'

const ws = new RbxSocket('wss://echo.websocket.org')
ws.on('open', () => ws.send('hello'))
ws.on('message', e => console.log(e.data))
Enter fullscreen mode Exit fullscreen mode

But it runs everywhere ws can't.

The problem with ws in 2026
ws @rabbx/ws
Install size 1.2 MB 6.4 KB
Gzipped ~300 KB 2.5 KB
Dependencies 14 0
Cold start 118ms 8ms
Cloudflare Workers ❌ Needs polyfills ✅ Native
Bun 🟡 Works ✅ Native
Deno ❌ Needs npm: ✅ Native
ws was written in 2011. The web moved on. It still ships bufferutil and utf-8-validate native bindings that break edge runtimes.

Cloudflare Workers gives you 50ms CPU time. import 'ws' eats 118ms before your code runs. You literally cannot use it.

Why 2.5KB matters

  1. Cold starts: Workers, Bun, Deno wake up in <10ms. Your deps shouldn't 12x that.
  2. Bundle size: 2.5KB gzipped is smaller than most favicons. Your WebSocket lib shouldn't be your biggest dep.
  3. Supply chain: 0 deps = 0 left-pad incidents. 0 CVEs. 0 node_modules surprises.
  4. DX: Same code locally and on the edge. No if (platform.env === 'workerd') checks.

Migrating from ws takes 30 seconds

npm uninstall ws
npm i @rabbx/ws
- import WebSocket from 'ws'
+ import { RbxSocket } from '@rabbx/ws'

- const wss = new WebSocket.Server({ port: 8080 })
+ const { 0: client, 1: server } = new WebSocketPair()
+ const wss = new RbxSocketServer(server)

- wss.on('connection', ws => {
+ wss.on('open', () => {
For clients, it's a drop-in:
- import WebSocket from 'ws'
+ import { RbxSocket } from '@rabbx/ws'

- const ws = new WebSocket('wss://...')
+ const ws = new RbxSocket('wss://...')
Enter fullscreen mode Exit fullscreen mode

We dogfood this

2M+ messages/day. 0 crashes. 8ms cold starts.

The post-npm era

Your deps have deps. Our tools have none.

We're building edge-native JS primitives. Zero dependencies. Web standard. Everywhere.

@rabbx/ws is just the start.

Star the repo if you're tired of npm bloat: https://github.com/rabbxdev/ws

Benchmark it. Break it. Roast me in the comments.


What's the heaviest package in your node_modules right now? I'll rewrite it next.


Top comments (0)