Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Also I thought one of the advantages of using a js framework is that rendering can be done on the client? It sounds from this article that server rendering is more advantageous?

Server rendering has advantages when first loading the SPA from the server: better user experience - faster loading because you don't need to wait for AJAX calls to do their round trips between browser and server to get data to populate the page - and better SEO - you don't need to rely on the search engine to correctly render the whole page.

With state changes after the initial load, though, client rendering is much better for UX (responsiveness). The whole point of "universal javascript" is that you can get both (initial server rendering and subsequent client rendering) with the same code base.



Can't one populate the initial state from the server to skip the extra round trip of the ajax call? Eg. dump a json somewhere on the page and have react load it from there, like a global JS variable.


I suspect that in most cases time spent loading the initial data is dwarfed by the initial app payload and turning the data into html.

Server-side rendering solves this by sending you a full 'screenshot' of the initial app, even before the app is downloaded and 'fresh' data is requested.

The clever thing React does in this use-case is that even though the initial load is 'finished' html, React won't have to re-render the entire thing once your app is loaded and requests new data. Instead, it will be able to seamlessly take over and update only what's new, and do its usual thing from there.

One issue you could run into is that users start trying to interact with your app before React has taken over. I'm not sure if that's a problem in practice though, perhaps others can chime in.


You can achieve that with almost any framework.


I never claimed otherwise, but yeah, it's not something unique to React.

Could you elaborate on how this works with other frameworks? Does it work out of the box in most cases, or require some plugin/module?


Yes, that's what's done but also you want the page to be server side rendered for SEO and may be for those who have js disabled.


There's that, or use something like python-react[0]. No js on the server required ;)

[0] https://github.com/markfinger/python-react




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: