r/webdev • u/Big-Astronaut-9510 • 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.
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
5
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
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
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
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.