3 ms·
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
by samsonradu 10y ago
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.
- nsomaru 10y agoThere's that, or use something like python-react[0]. No js on the server required ;) [0] https://github.com/markfinger/python-react https://github.com/markfinger/python-react
- nitely 10y agoYes, 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.
- mercer 10y agoI 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.