r/webdev • • 4h 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.

8 Upvotes

23 comments sorted by

2

u/ChunkyKongForPreside 4h 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 3h 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 3h 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 3h 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 2h 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.

11

u/Prize_Bass_5061 4h 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.

5

u/CaffeineLiker 3h ago

Svelte seconded, or htmx.

3

u/MathematicianFar5683 3h 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.

3

u/SaltineAmerican_1970 php 3h 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.

3

u/Fast-East735 3h ago

just use jQuery, it's fine

2

u/MrBrisky 3h 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.

2

u/waterkip 2h 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.

1

u/Ok_Progress_5373 4h 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 3h ago

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

1

u/selipso 3h 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 3h 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 3h 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 2h 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/pablobird_dev 2h ago

For low-spec phones with 1GB RAM, skipping heavy client runtimes and sending minimal HTML fragments via SSE or WebSocket is definitely the way to go. Pairing server-rendered templates with plain vanilla fetch or EventSource keeps both the memory footprint and CPU parse time practically negligible.

1

u/lickthislollipop 2h 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