Rendering React components on the server
In the previous section, we identified cascading requests as the problem for our bad performance on slow connections. Possible solutions to this problem are as follows:
- Bundled requests: Fetch everything on the server and then serve everything at once to the client in a single request. This would solve the cascading requests when fetching author names, but not the initial waiting time between the HTML page being loaded and the JavaScript executing to start fetching the data. With a latency of two seconds per request, that’s still four seconds added (two seconds for loading the JavaScript and two seconds for making the request) after the HTML is fetched.
- Server-side rendering: Render the initial user interface with all data on the server and serve it instead of the initial HTML that just contains a URL to the JavaScript file. This would mean that no additional requests are needed to fetch the data or JavaScript and we can show...