Hacker News new | ask | show | jobs
by freecodeio 29 days ago
that still doesn't answer the question, are you suggesting to maintain 1 giant string that represents the whole page whereby document.innerHTML is called everytime the string changes, or are you suggesting something else?
1 comments

There is JS in the browser and will update a small part of the page by requesting HTML snippets from the server, not JSON payloads. Look at the Turbo+Stimulus framework. Its shipped as a library in Rails but it can be standalone - I built a small local webapp with it and the backend was Golang.

Read more here: https://turbo.hotwired.dev/handbook/introduction

Elixir has a similar mechanism with Phoenix LiveView.

Frontend has exploded in complexity. Separating concerns whereby the frontend does not care about the backend leads to better quality.

Just rendering a simple e-mail client on page 5 of a search result is simple enough to understand that streaming html for that state would require rocket science of string manipulation.

Besides that, you still did not answer how is updating the entire innerHTML for small changes better than just updating affected nodes?

I don't think you're understanding or reading what I linked to. The entire innerHTML of the page is not getting updated. If it was a page showing emails and there were next/prev buttons, next could trigger just the div (or area of the page that shows the list of emails) to reload with the server determined next 25 emails in an HTML snippet. The navigation areas don't change at all on the page, the page and browser don't go through a full refresh at all. There isn't a payload of JSON objects to parse and store in memory, nor a set of APIs to build on the server that output JSON.

Frontends have not exploded in complexity, they are still manipulating a DOM like they have been for 25 years. Complexity was writing different JS implementations for different browsers like Netscape Navigator 4 and Internet Explorer 4. I think a lot of frontend complexity is simply because of JS framework proliferation and a stance that the entire application should be JS in the browser, a full MVC framework when the backend is likely a full MVC framework already and has to validate all the inbound data changes.

What we're arguing about is mostly preference at this point. Please check out what different server frameworks do, there are server side JS frameworks too. If you're building simple web sites (like a pizza restaurant) vs. building a web application (like an app that processes millions of financial transactions per day) then the approach is going to be different and there are trade-offs to be made when picking a tech stack.