| >Rendering HTML server-side is just nice No, rendering html server-side is not nice and never was. Why on earth you will send markup template for every list item over and over again instead of sending just data and only one code-template (to render data on a client) ?
Suppose you need to show to user a list of books on your web-page. Server side rendering means you need to send to user a markup consists of html elements for every book <div>
<div class="book">
<div class="book-title">Book 1</div>
<div class="book-author">Author 1</div>
<div class="book-description">..description..</div>
</div>
<div class="book">
<div class="book-title">Book 2</div>
<div class="book-author">Author 1</div>
<div class="book-description">..description..</div>
</div>
<div class="book">
<div class="book-title">Book 2</div>
<div class="book-author">Author 2</div>
<div class="book-description">..description..</div>
</div>
</div>
... Don't you see something wrong with this? Why you need to duplicate over and over again html template for every list item resulting of significant increase of size of page to download if you can send only one template-component like this <div>
<div class="book">
<div class="book-title">{book.title}</div>
<div class="book-author">{book.author}</div>
<div class="book-description">{book.description}</div>
</div>
</div> and a data in a more compact way [{title: "Book 1", author: "Author 1", description: "..."}, {title: "Book 1", author: "Author 1", description: "..."}, ...] or more compact like this [["Book 1", "Author 1", "..."],["Book 1", "Author 1", "..."], ...] or even in more compact binary-encoded format resulting in more than magnitude size compaction comparing to over-duplication html-approach. More size means more traffic for users to download over network and users which use data-roaming will "thank" you for your hundreds of kilobytes instead of dozens This is why server-side rendering approach was flawed from the beginning (not because of page reloading but because of data duplication and traffic consumption) |
- to turn the JSON into HTML, you not only need the template you mentioned, you also need code to execute that template (potentially lots of it); preact is 10KB ungzipped (other frameworks, like React/Angular/Ember, are way larger), so your HTML solution is already 10,000 characters ahead (by comparison, the markup you demoed is ~90 bytes per book, so you’re ahead until at least ~100 books on the page, without considering the framework, your code, and the following points)
- HTML compresses amazingly well because it’s repetitive so the overhead is less than you think
- HTML stream renders, so you can start rendering the first book immediately; JSON streaming is technically possible, but not built-in, and quite difficult to implement (and it requires even more JS)
- the same KB of JS is way more expensive than it would be as HTML (or images) because parsing, compiling, and executing is slow
- latency is often a larger problem than bandwidth, especially on mobile, so saving bandwidth is less important than (a) streaming and (b) client-side blocking time
- a large number of users visit one page and bounce, for typical websites, so the promised savings once the SPA is live doesn’t materialize
- the naive way to implement a SPA is _full_ of footguns; first of all, you’d naively load the template for all the pages, making the overhead problem even worse, naively you wouldn’t render anything until the JS has arrived, delaying the TTFMP enormously, naively you’d mess up routing, etc.
- it’s relatively trivial to preload/precache HTML pages, including in a service worker to support offline, making performance on par or better than a SPA
I happily work on a huge SPA daily, for context.