Gufran Mirza
Software Engineer @Continuum
Twitter: _imGufran
Overview - React Client Side Rendering
Overview - React Server Side Rendering
Performance CSR vs SSR
Live Demo
Discussion
Server-Side Rendering is the ability of a front-end framework to render markup while running on a back-end system.
Faster times for the initial page render
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="shortcut icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no" />
<title>React App</title>
<link href="/static/css/main.css" rel="stylesheet">
<script src="/static/js/main.js"></script>
</head>
<body>
<div id="root"></div>
</body>
</html>
Browser downloads the Javascript and then executes it to generate the Content
GET - /
SERVER
index.html
<!DOCTYPE html>
<html>
<head>
<title>Pup vs Pup</title>
<link rel="stylesheet" href="/css/style.css">
<script src="public/bundle.js" defer></script>
</head>
<body>
<div id="app"></div>
</body>
</html>
User View
GET - /public/bundle.js
SERVER
bundle.js
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
....
21,547 MORE LINES OF CODE
But where are the pups???
PuppyDB
GET - /api/puppies
GET - /
1
SERVER
GET - /bundle.js
2
React.DOM Render
3
React.DOM Render
5
GET - api/puppies
4
"First Meaningful Paint"
GET - /style.css
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="shortcut icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no" />
<title>React App</title>
<link href="/static/css/main.css" rel="stylesheet">
<script src="/static/js/main.js"></script>
</head>
<body>
<div id="root"></div>
<div id="root">
<div class="App" data-reactroot="">
<header class="App-header">
<img src="[object Object]" class="App-logo" alt="logo" />
<p>Edit <code>src/App.js</code> and save to reload.</p>
<a class="App-link" href="https://reactjs.org" target="_blank" rel="noopener noreferrer">Learn React</a>
</header>
</div>
</div>
</body>
</html>
Server (NodeJS) renders the App and generates the content at server-side and returns the generated content
Server Side React - Overview
GET - /
1
SERVER
React.DOM Render
2
React DOM renders again on client side
Downloads js
Light Hose Report - CSR
Performance Report - CSR
Light Hose Report - SSR
Performance Report - SSR