Illustration of web push vs websockets, three connection paths between a server and a laptop with a notification bell Illustration of web push vs websockets, three connection paths between a server and a laptop with a notification bell

Web Push vs WebSockets vs Server-Sent Events: Which Should You Use?

Web push vs WebSockets vs Server-Sent Events: what each does, which works with the page closed, costs, and when to combine them.

Use web push when you need to reach people after they’ve left your site, because it works with the tab closed. Use WebSockets for fast two-way messaging while a page is open, such as chat or live collaboration. Use Server-Sent Events for one-way live updates to an open page, like scores, prices or progress bars.

Developers ask me about web push vs WebSockets more often than you’d think. The confusion makes sense: all three technologies push data from a server to a browser. However, they solve different problems, and picking the wrong one leads to either missed messages or a lot of unnecessary infrastructure. Here’s how I decide.

Key facts at a glance:

  • Web push (RFC 8030 plus the W3C Push API) goes through a browser-run push service and can show a notification when your site isn’t open.
  • WebSockets (RFC 6455) keep one open, two-way connection between a page and your server.
  • Server-Sent Events (the EventSource API in the HTML standard) keep an open, one-way HTTP stream from your server to a page.
  • Only web push needs the visitor’s permission, and only web push works with the page closed.
  • WebSockets and Server-Sent Events stop the moment the visitor closes the tab.

What is the difference between web push, WebSockets and Server-Sent Events?

The main difference is whether the page needs to be open. WebSockets and Server-Sent Events are live connections to an open page. Web push is a message delivered by the browser’s push service, even when no page from your site is open.

Web pushWebSocketsServer-Sent Events
DirectionServer to browserTwo-wayServer to browser
Works with the page closedYesNoNo
Needs user permissionYes, notification permissionNoNo
Connection held byBrowser and push service (for example FCM)Your serverYour server
Shows a visible notificationYes, alwaysNo, your page decidesNo, your page decides
Payload sizeUp to 4,096 bytes encryptedLarge messages allowedText events, large allowed
Typical useNews alerts, offers, remindersChat, games, collaborationLive scores, prices, logs

When should you use web push?

Use web push when the message is worth interrupting someone for and they aren’t on your site. That covers new article alerts, price drops, abandoned carts, order updates and reminders.

Web push has three properties the others don’t. First, your server doesn’t hold a connection to every visitor; the browser’s push service, such as Firebase Cloud Messaging (FCM), does that. Second, the browser wakes your service worker to show the notification even if your tabs are closed. Third, on desktop and Android, the notification appears in the operating system’s notification centre.

The trade-off is control. You need permission, each message must show a visible notification, and the payload is small. My guide on whether web push works when the browser is closed covers the delivery limits.

When should you use WebSockets?

Use WebSockets when the browser and server need to talk back and forth quickly while the page is open. Chat apps, multiplayer games, collaborative editors and trading dashboards are the classic examples.

A WebSocket starts as an HTTP request and upgrades to a persistent two-way channel. Either side can send messages at any time, with very little overhead per message. As a result, it suits high-frequency updates in both directions.

The cost sits on your side. Every open tab holds a connection to your server, so you need servers, load balancers and proxies that handle many long-lived connections. When the visitor closes the tab, the connection ends and you can’t reach them anymore. MDN’s WebSocket API page is a good starting point.

When should you use Server-Sent Events?

Use Server-Sent Events when only the server needs to send updates to an open page. Live scores, stock tickers, build logs, progress bars and AI responses that stream word by word all fit this pattern.

Server-Sent Events run over plain HTTP. The browser’s EventSource object opens a stream, and the server writes text events to it. EventSource reconnects automatically if the connection drops, which is less code than a WebSocket for one-way updates.

There’s one limit to know. Over HTTP/1.1, browsers allow only about six connections per domain, so several tabs with SSE streams can block each other. MDN’s Server-sent events guide notes this; HTTP/2 removes most of the problem.

Can you use web push and WebSockets together?

Yes, and many products do. The usual pattern is to use a WebSocket or SSE stream while the user has your site open, then fall back to web push once they leave.

A chat app is the clearest example. While the conversation is open, new messages arrive over the WebSocket instantly. When the tab is closed, the server sends a web push instead, so the user still hears about the message. Your server simply checks whether the user has an active connection before choosing a channel.

The same idea works for a news site. A live blog page can stream updates over SSE, while subscribers who aren’t on the site get a web push for the biggest story of the day.

Which one is cheapest to run?

Web push is usually cheapest for reaching people outside your site, because the push service holds the connections. WebSockets and SSE cost you server resources for every open tab.

Who keeps connections openWhat you pay for
Web pushPush service (FCM, Mozilla, Apple)Your sending server or push provider
WebSocketsYour serverServers sized for concurrent connections
Server-Sent EventsYour serverServers sized for concurrent connections

For web push, the main choice is between a hosted service and running your own sender. My breakdown of the cost of running a push notification server covers the numbers.

Can WebSockets or SSE replace web push?

No. Neither can deliver anything once the page is closed, and neither can show a system notification on its own. A page could call the Notifications API to show an alert while it’s open, but that only works while the visitor stays on your site.

On the other hand, web push can’t replace WebSockets either. It isn’t built for high-frequency or two-way data, and browsers don’t allow silent background pushes. I covered that limit in my post on silent web push notifications.

Where LaraPush fits

LaraPush covers the web push side of this picture. It’s a self-hosted web push panel that you install on your own VPS, with a one-time licence from $499 (check LaraPush pricing). It sends through Firebase Cloud Messaging and includes a REST API, so your app can trigger a web push when a user isn’t connected. The features page lists the rest. It doesn’t provide WebSocket or SSE hosting. The trade-offs are no free plan and a server you maintain. For other options, see my roundup of the best push notification services and tools.

Frequently asked questions

Does web push use WebSockets?

Not in a way you control. Browsers keep their own connection to a push service, such as Firebase Cloud Messaging, Mozilla autopush or Apple’s service. Your server sends an HTTP request to that service, which then delivers the message. You never open a WebSocket yourself to send web push.

Are Server-Sent Events better than WebSockets?

They’re better for one-way updates. SSE uses plain HTTP, reconnects automatically and needs less code. WebSockets are better when the browser also sends frequent messages, as in chat or games. If the browser only listens, start with SSE; if it talks back often, use WebSockets.

Do WebSockets work when the browser is closed?

No. A WebSocket lives inside an open page. When the visitor closes the tab or the browser, the connection ends and your server can’t reach them. To reach people who have left your site, you need web push or another channel such as email.

Can I send a web push notification without asking for permission?

No. Every browser requires the visitor to allow notifications for your site before you can subscribe them. WebSockets and Server-Sent Events don’t need permission, but they also can’t show anything after the page closes. Ask for push permission at a relevant moment for better results.

Which should I use for a real-time dashboard?

Use Server-Sent Events or WebSockets for the dashboard itself, because updates are frequent and the page is open. Add web push only for important alerts, such as a failed payment or a server outage, so the right person hears about them even when the dashboard isn’t open.

Leave a Reply

Your email address will not be published. Required fields are marked *