Rara’s order news comes three ways: setInterval (bikes back and forth), long-poll, or an EventSource (the gudang’s phone line). How many requests go out, how…
Notifications, order status, changing prices, build logs: many pages need news from the server without asking. Polling is easy but wasteful and late; long-polling is quick but opens a new request for every piece of news; SSE (EventSource) uses one HTTP response that never closes, reconnects by itself, and is enough for one-way news. For fully two-way, then WebSocket.
Who starts it: the page asking, or the gudang writing
setInterval(fetch, 1000) to feel realtime Every user asks every second, news or not: most requests come home empty, and news is still late until the next tick plus a round trip. If the news comes from the server and must be quick, use long-polling or EventSource.EventSource only listens: there is no send(), so es.send() throws a TypeError. To talk to the server, send a request of your own with fetch (POST). Need two-way all the time (chat, games)? Use a WebSocket.EventSource waits the retry: time and asks again with Last-Event-ID, as long as the server writes id: on every piece of news; with no id:, the news during the drop is lost. On HTTP/1.1 browsers allow about 6 connections per domain, so many SSE tabs can stall; HTTP/2 shares one connection.fetch, taking one chunk for one piece of news The network cuts bytes anywhere: one piece of news can come in two chunks, or two in one. An event only ends at a blank line. Keep the unfinished line in a buffer as the EventSource parser does (and a TextDecoder with stream: true); never JSON.parse a chunk.setInterval every second Half the requests come home with nothing, and news is nearly a second late.EventSource One request for all five pieces of news, each only one ride.Last-Event-ID.