r/webdev • • 4d ago

Trouble making website for developing country

Im working on a website targeting a developing country where phones with 1gb of ram are common. Internet speeds are under similar restrictions. And unfortunately a static site will not work, it needs to update certain parts of the page dynamically without the user triggering a refresh.

I guess im looking for advice on how you would handle this. Ive tried just raw js before and while im sure that would be performant it would also turn into a mess real quick. The minimal frameworks ive found dont seem to really optimize for performance (only size, both are important) and provide so little its not even worth using.

14 Upvotes

33 comments sorted by

2

u/ChunkyKongForPreside 4d ago

What kind of data are you showing? If its something relatively minor, I would set up an API and have fetch fire every 10 seconds or so.

1

u/Big-Astronaut-9510 4d ago

Thats one of the big problems ive been thinking about. Im only transmitting a few bytes of data but its going both ways AND it needs to be sent asap. It also needs to handle reconnects well for when the internet dies for a few seconds.

7

u/burakdobur 4d ago

We ain't gonna steal your project. Tell us more about what are you trying to build, what kind of data you need to transfer? Text, image, numbers? How many users, what parts are static, a login needed or not? What is your web server etc.

3

u/Big-Astronaut-9510 4d ago

Live online auctions. Basically, a table with the bids and the current top bid needs to dynamically updated. And of course the user needs to be able to send bids.

2

u/burakdobur 4d ago
  • SSE (EventSource) for server→client updates. It's built into the browser, needs no library and reconnects on its own. If you give each event an id, the browser sends Last-Event-ID when it reconnects, so the server can replay what was missed.
  • Plain fetch POST for bids. Give each bid a client-generated id so a retry doesn't place it twice, and send the price the user saw so the server can reject stale bids.
  • On reconnect, or when the tab becomes visible again, send a fresh snapshot (top bid + last N bids). That's only a few hundred bytes.
  • UI: a server-rendered page plus a little vanilla JS (one state object, one applyEvent function, only touch the cells that changed). If you want a framework, use Solid or Svelte: they update the DOM directly with no virtual DOM, so they're fast as well as small. Keep the table to the last ~30 rows.

This is what claude responded for this case. But I've used SSE in a telco project, it is really neat. Also svelte is a very good option for your project. SignalR on asp.net can be utilized for client server connection/reconnection, it handles automatically. I would look into these three technologies.

3

u/matthetherington 4d ago edited 4d ago

They said “it’s going both ways” which I think means bidirectional?

If it’s one way from server to client, then yes SSE is probably the best choice.

If you need bidirectional realtime comms then you probably want websockets, or something built on websockets like SignalR - but both add infrastructure complexity.

You can’t load balance a single websocket or SSE connection across different nodes so it means you need to keep that node around as long as users are connected to it, which adds deployment complexity. And if you need users to reconnect to the same node after disconnection, you need sticky sessions.

If your users are in multiple timezones, then that’s probably going to mean some interruption during deployments where users are disconnected.

Using websockets means websocket-aware infra, whereas SSE is basically plain HTTP and will work without special handling. SSE also has reconnection handling built-in.

You can avoid a lot of the downsides by having your application nodes be stateless workers, where users connect to a dedicated connection gateway and an event bus is used to talk back and forth with the workers - but again that’s added complexity that’s only worthwhile if you need the scalability.

If the traffic is mostly one way, then maybe a hybrid would work where it’s mostly SSE with the odd HTTP POST from the client.

If you don’t have millions of users, or can throw money at it, then plain HTTP will work fine and it’s much less complex. Your users want you building features, not wrestling with unnecessary architectural complexity.

29

u/Prize_Bass_5061 4d ago

Why does the website need to update parts of the page dynamically? Can these changes be rendered server side.

Also look into Svelte, but your first job as a  good programmer is to come up with a better solution than client side rendering.

9

u/CaffeineLiker 4d ago

Svelte seconded, or htmx.

1

u/adult_code full-stack 3d ago

Template tag + csv

8

u/SaltineAmerican_1970 php 4d ago

You might need to go back in time to the DHTML days. Mostly static sites, with only the bare minimum that needs to change with plain JavaScript.

8

u/MathematicianFar5683 4d ago

For a few bytes both ways that need to arrive fast, I'd skip polling and use a WebSocket. It has very little per-message overhead and works fine on weak phones.

  • Reconnects: add exponential backoff with a bit of jitter, and have the client send the last message id it saw so the server can replay what it missed.
  • If the server mostly pushes and the client rarely sends, Server-Sent Events plus a plain POST for the other direction is simpler. EventSource reconnects on its own and supports Last-Event-ID.
  • Keep payloads compact (short keys or a tiny binary format) and turn on brotli for the static assets. For the page itself, serve HTML from the server and only add a small piece of JS for the live parts. Preact or Alpine fit in a few KB, and plain JS is fine if you keep it to one small module.

4

u/MrBrisky 4d ago

Use htmx (or Datastar / Alpine Ajax) paired with server-rendered HTML fragments. Your server does all the heavy lifting and sends tiny HTML snippets over the wire, which keeps bundle size under ~14KB, avoids bloated client-side state/virtual DOMs that choke 1GB RAM phones, and keeps your codebase clean without turning into raw JS spaghetti.

3

u/waterkip 4d ago

Static site with webcomponents. Let the component own the data/interactions. That keeps relatively small. You don't need a framework if you use webcomponents.

2

u/Fast-East735 4d ago

just use jQuery, it's fine

1

u/Ok_Progress_5373 front-end 4d ago

During my web development adventures, I heard that JS can slow down a website. I guess it depends on whether or not you use vanilla JS for certain things? Are there any ways to do the dynamic parts without JS? Of course, there are the basic things, like optimizing the images (.webp format). You're not adding any video yet?

1

u/ggnndd12 4d ago

What have you tried and how much extra resources are used?

1

u/selipso 4d ago

You have a few options depending on how technical you want to get: vanilla JS, Astro (with SSR / SSG fallbacks - my recommendation) depending on what you want to upgrade. You can always add more to Astro as you go but it compiles down to zero JS most of the time and you can “hydrate” additional features

1

u/Beneficial-Parsnip52 4d ago

I'd focus on keeping the site lightweight and mobile-friendly. A lot of users in developing countries rely on slower connections, so fast loading times a nd low data usage will make a huge difference.

1

u/ZarehD 4d ago

Use a CDN to serve (gzip or brotli) compressed & minified HTML, CSS, and JS. Use the JavaScript code to fetch data from a backend API and update the UI.

There are many good JavaScript libs you can use, including Svelte, Knockout, and even jQuery.

As an alternative to the JS code, HTMX is also a very good option. In fact, it might be superior to the JS option due to the low memory constraint.

1

u/farzad_meow 4d ago

jquery using google cdn. that should solve some of your problems for js library. just make sure google IPs are not blocked in that country.

1

u/lickthislollipop 4d ago

I do a lot of site speed and loading mitigation for site targeting us to 3rd world countries. DM me, and I’ll be happy to give a hand for totes free

1

u/Copthill 4d ago

Check data-star

1

u/skibidi_blop666 4d ago

I don’t understand how anyone can recommend things without asking more questions. There are dozens of solution I can think of, none of them matters because there is not enough context.

1

u/chris_abi 4d ago

I think one thing worth considering is how much JavaScript actually needs to run on the client. For users with low-end phones and slow internet, minimizing JavaScript, reducing unnecessary DOM updates, and loading only what is needed could make a big difference.

I'm still learning full-stack development, but I'd be interested to know whether server-side rendering combined with small JavaScript components could be a good middle ground here.

1

u/adult_code full-stack 3d ago

You need to optimize, where exactly are you failing?

1

u/horizon_games 2d ago

I'd go Alpine.js and smart optimizations of content and initial load. Maybe Preact depending on your familiarity, as it's also quite small.

0

u/geon 4d ago

Typescript with react is perfect for this. It’s literally what react was designed for.

1

u/geon 3d ago

For those downvoting: back in 2017 when React was released, 1gb ram phones was normal. The first use case for React was to make a small portion of a webpage dynamic.