Three similarly named browser technologies, three different jobs
Web Sockets, Web Workers and Service Workers are easy to conflate: the names sound alike and they rarely come up in the same conversation. The quick reference below compares them at a glance, and the sections that follow expand on each.
| Feature | What it is |
|---|---|
| Web Socket | Establishes an open and persistent two-way connection between the browser and server to send and receive messages over a single connection triggered by events. |
| Web Worker | Allows scripts to run in the background in separate threads to prevent scripts from blocking one another on the main thread. |
| Service Worker | A type of Web Worker that creates a background service that acts middleware for handling network requests between the browser and server, even in offline situations. |
Web Sockets: a persistent, two-way channel
A Web Socket is a two-way communication protocol. Picture an ongoing call with a friend that continues until one side hangs up — except the two parties are the browser (client) and the server, and each can send requests to the other. Communication is event-based: a WebSocket object connects to a server, and incoming messages trigger the events that send and receive them.

Once the connection is opened it stays alive until the client or the server terminates it with a CloseEvent. That makes Web Sockets a good fit for applications needing continuous, direct client–server communication. Chat apps are the textbook case: you send a message, an event fires, and the server returns data without repeated polling. A maps app that tracks your location in real time for as long as the connection lives is another; so is a sports app pushing live scores.
The decisive difference from the other two technologies is DOM access. Web Sockets belong to the main thread and can therefore manipulate the DOM, whereas Web Workers and Service Workers run on separate threads and cannot.
Several tools and services help establish and maintain Web Socket connections, including SocketCluster, AsyncAPI, cowboy, WebSocket King, Channels and Gorilla WebSocket. MDN maintains a running list of additional services.
Web Workers: background threads for heavy work
JavaScript is single-threaded, so running several scripts at once — say, a batch of complex calculations alongside DOM updates — can disrupt both the interface and the calculation itself. Web Workers solve this by running scripts in the background on separate threads, keeping them from blocking one another on the main thread.
That improves performance for intensive operations, which can proceed in the background without interfering with rendering. The trade-off: because a worker runs in its own thread rather than the main thread, it is poor at DOM access. A worker is an object that executes a script file via the Worker object.
Workers come in three types:
- Dedicated Workers: reachable only by the script that created them, while still providing the usual multi-threaded execution.
- Shared Workers: accessible to multiple scripts, and able to do essentially anything a web worker does, provided those scripts share the worker's domain.
- Service Workers: a network proxy between app, browser and server that lets scripts run even when the network drops.
Service Workers: an async proxy between app and network
Developers do not control the user's network connection, only how well an app performs on it. A Service Worker is a progressive-enhancement measure: it sits between the app, the browser and the server as a secure connection running in the background on its own thread — because, as noted above, a Service Worker is one of the three Web Worker types.
When the connection fails, communication between browser and server breaks and data stops flowing. The service worker keeps things working by acting as an async proxy that intercepts requests and executes tasks even after the network is gone.

This is the engine behind "offline-first" development: caching assets locally instead of over the network, showing critical information when the user goes offline, prefetching resources ahead of need, and serving fallbacks on network errors. Service Workers are fully asynchronous, but unlike Web Sockets they have no DOM access, since they run on their own threads.
Two consequences follow from the fact that a service worker intercepts every request and response from the app. It is bound by a same-origin policy, so you cannot run one from a CDN or third-party service. And it requires a secure HTTPS connection, meaning you need an SSL certificate for it to run.
Comparison, expanded
The table below extends the earlier quick reference with the same comparison points.
| Feature | What it is | Multithreaded? | HTTPS? | DOM access? |
|---|---|---|---|---|
| Web Socket | Establishes an open and persistent two-way connection between the browser and server to send and receive messages over a single connection triggered by events. | Runs on the main thread | Not required | Yes |
| Web Worker | Allows scripts to run in the background in separate threads to prevent scripts from blocking one another on the main thread. | Runs on a separate thread | Required | No |
| Service Worker | A type of Web Worker that creates a background service that acts middleware for handling network requests between the browser and server, even in offline situations. | Runs on a separate thread | Required | No |



