On every incoming request, the server:
- creates the store/initial app state
- matches the URL to find the right component
- loads the component and gets the HTML
- sends the HTML back to the client
Then, the client loads the JavaScript app.
- Accessibility (limited)
- Better performances (first meaningful paint)
- Better user experience (JS disabled)
- Search Engine Optimization/Social sharing
- Quite good at browsing JS apps
- Give up after ~10 seconds
- Some issues with
react-router
Source: Testing a React-driven website’s SEO using “Fetch as Google”, Nov. 2016.
- Makes everything very complicated
- Time To First Byte (TTFB) usually slower (but Cloudfare says it's fine in [1])
- React
renderToString()
holds the event loop [2], probably also the case for other frameworks
[1]: Stop worrying about Time To First Byte (TTFB)
[2]: The Benefits of Server Side Rendering Over Client Side Rendering
- Two different environments, one codebase
- Cookies, redirects/errors, HTTP statuses
- Data fetching before rendering
+ isomorphic libraries and polyfills
You have to find hacks nice tricks 👻
There used to be two approaches...
- static
async
method to fetch data andPromise.all()
on the server - double render 💔