The site needs to update parts of the page without a refresh, but some users may have phones with 1 GB of RAM and slow connections. How can I keep it responsive without ending up with a mess of plain JavaScript?
How would you build a live-updating site for low-spec phones?
Answers
Start by separating the parts that actually need live updates from the rest of the page. Render the initial page on the server, then update only those sections. You don't necessarily need to render the whole interface in the browser.
Server-rendered HTML fragments are one option. A library such as htmx can swap those fragments into the page without making you write all the request and update plumbing yourself. The server still needs to produce the fragments, and their size depends on what you send, so measure the traffic rather than assuming it'll be tiny.
Reply to this answer
The update frequency matters here. If the information can be a little stale, a small fetch request every so often might be enough. If updates need to arrive quickly, look at Server-Sent Events for mostly server-to-browser updates, or WebSockets when both sides need to send messages.
For a persistent connection, plan for dropped mobile connections. Reconnect with exponential backoff and jitter, and consider sending the last message ID the client received so the server can replay missed updates if it supports that.
Reply to this answer
Plain JavaScript doesn't have to mean one giant script. Put each interactive area in its own component or module and keep its data and update logic together. Web components are one way to organize that without adopting a full framework.
If that still feels like too much plumbing, try a small library or a compiled framework such as Svelte. Bundle size alone won't tell you how well it runs, though. Compare the actual work and memory use on a constrained device.
Reply to this answer
Don't spend the whole budget arguing about frameworks while shipping huge images. Resize and optimize images, compress and minify HTML, CSS, and JavaScript, and consider a CDN that users can actually reach. Keep an eye on the total data used by updates too, not just the first page load.
Reply to this answer
Before picking a stack, test a small version of the actual page on a low-memory phone and a slow connection. Measure load time, memory, and how the page feels while updates arrive. That gives you something concrete to compare when a library claims to be lightweight.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Veldmari-6q:
Polling can be simpler to maintain, but check how many requests it generates across all your users, not just on one phone.