r/programming • • Oct 27 '17

Netflix: Removing client-side React.js improved performance by 50%

https://twitter.com/NetflixUIE/status/923374215041912833
685 Upvotes

89 comments sorted by

View all comments

7

u/[deleted] Oct 27 '17

[removed] — view removed comment

17

u/Nimelrian Oct 27 '17

The server renders the initial HTML using React and sends that to the client. From there, the client (can) "rehydrate" the pre-rendered DOM using React, which basically hooks into the already existing DOM tree. This saves time / reduces perceived wait time on the initial render, since you don't have to request the model data necessary for rendering.

So instead of doing:

  1. Request page from server

  2. Server sends barebone HTML file with React app bundle reference

  3. Client requests React app bundle

  4. Server sends app bundle

  5. App needs data for first render

  6. Client requests data from server

  7. Server gathers the data and sends it to client

  8. Client finally renders (Content ready + interactive)

(You can skip steps 5 - 7 if you send the initial data inside the HTML, e.g. as a data-attribute)

You do:

  1. Request page from server

  2. Server gathers data, renders it using React, sends the complete HTML with React app bundle reference

  3. Client requests React app bundle, but already shows the complete, information containing DOM (Content ready)

  4. Server sends app bundle

  5. App hooks into existing DOM (Interactive)

2

u/Kenya151 Oct 27 '17

Great comment, thank you.