Hacker News new | ask | show | jobs
by charliesome 5024 days ago
People have this belief that server side templates are slow.
3 comments

For certain applications, they are.

If I have a single page web app, I don't want the overhead of returning markup. I just want JSON. And when I get raw data back instead of a string of HTML, I can be a lot smarter about responding to user input (e.g. optimistic updates).

Well, you send something to the server, then the templating happens, and then it's sent back to you. Even indefinitely fast templating would be slow due to network latency.

Also, sending JSON back and forth is kinda nice because it's fairly compact, easy to handle on both sides, and additionally this particular API may be used for other purposes, too.

Is this said in good faith? There are lots of reasons for client side templates, but I rarely (never) see anyone citing it because rendering on the server is slower than rendering on the client.
Client-side rendering probably isn't faster than server-side rendering in terms of latency, but it is cheaper. You save on server processing and network bandwidth.

Rendering speed isn't the reason server-side templates feel "slow" though: if you do server-side rendering then every change of state on the client needs to round-trip to the server in order to fetch a new HTML representation. Client-side rendering lets you "cheat": just render the new state and synchronize with the server after the fact.

Right.