-
Client-Side Rendering (
CSR) -
Server-Side Rendering (
SSR)
SPA (Single-Page Apps) - each page is rendered on the client, not on the server
- the server serves up a single static
index.htmldocument - the browser then parses
HTML& loadsCSS,JS,img& fonts - the
JSbundle, once loaded, fetches data from anAPI& constructs theDOM - the user navigates between routes via the
history API, not page reloads - the app lazy-loads remaining
JSchunks on demand (code splitting) - the site can be served from a
CDNto speed up the load time
- decreased load on the server
- better UI/UX interactivity
- static hosting & caching
- decoupled architecture
- slow initial render
- heavy
JSdependency - non-SEO friendly
- poor accessibility
- initial render depends on
JS, and can thus be very slow- bundle size (framework + app code), network latency, hardware limitations
- the page is technically ready to render once
HTML&CSSare loaded- it doesn't need to wait on JS to load & execute before it can paint
MPA (Multi-Page Apps) - each page is rendered on the server, not on the client
-
the server serves up a new
HTMLdocument on each request -
the browser loads & parses
CSSto paint the UI -
the browser then loads & parses deferred
JSto enhance the UI* -
the user navigates between routes by requesting a new page
-
the browser caches assets (
CSS,JS,img, etc.) for faster page load (just like withCSR) -
the server can cache static
HTMLon aCDNto decrease the load
* JS can be made non render blocking; often done by
<script>at the end of body to only load blockingJSafter other assets<script defer>attribute to continue parsingHTMLwhile loadingJS
- fast first meaningful paint
- better perceived performance
- SEO-friendly
- increased load on the server
- latency due to page requests / reloads
- low UI/UX interactivity
Case in Point: Walmart
React is isomorphic (universal)
- can run in a browser, server, native app, or VR headset
- app can be server-rendered for faster paint
- then client-rendered to take over as an
SPA!
- the server pre-renders the app into an
HTMLstring and serves it up - the browser loads & parses
CSSto make the page viewable - the browser then loads the
JSbundle and boots the React SPA to make it interactive - React doesn't need to re-render if server and client markup are identical
-
zero configuration incubator for single-page React apps by Facebook
-
sets up a dev environment with a bundler, transpiler, linter, test runner, & live server
-
Bundler: bundles up assets (
JS= modules + deps,CSS,img, fonts, etc) -
Transpiler: transforms ES6+ down to ES5 for better support across browsers
-
Linter: anaylizes source for stylistic & logical errors (formatting, spacing, etc.)
-
Test runner: allows for unit testing and code coverage reports
-
Live server: dev server that watches files, and recompiles and auto-reloads as they change
Philosophy (from README.md)
- One build dependency (react-scripts:
Webpack,Babel,ESLint, etc.) - Zero configuration (sensible defaults, optimized production build)
- No lock-in (beginner-friendly customizable setup)
- Learning React & tooling
- SPA or static sites
- Rapid prototyping, demo apps, side projects
- ES6+ support
- stage 2 (draft), 3 (candidate) & 4 (finished):
async/await, dynamicimport(),class fields, etc. +JSX&Flow - but not stage 1 (proposal) or 0 (strawman) (e.g.
do expressionsorfunction bind ::) - also doesn't support
@decorators(stage 2)
- stage 2 (draft), 3 (candidate) & 4 (finished):
- Polyfills
- but only few:
Promise,fetch,Object.assign - and not others:
Array.find,Array.includes,Symbol,Intl - will need to install & cherry-pick from
core-jsorbabel-polyfill
- but only few:
- Linting
- comes with
ESLint, but needs a plugin for the editor, and/orPrettierfor auto-formatting
- comes with
- Testing
Jesttest runner withjsdomto write test cases & assertions- doesn't isolate component that's being tested from its children
- for isolated unit tests still need
Enzymeor react-testing-library (withjest-dom)
- Optimizations
- minifies, uglifies, and compresses code for prod. build
- also includes hashes (for caching) and source maps (for debugging)
- may need a tool e.g.
source-map-explorerto analyze bundle size
- Out of Scope
- CI/CD (
TravisCI,CircleCI) - Deployment (
Firebase,Now,Surge) - UI/UX or other libraries (
Bootstrap,Material-UI) - though well documented
- CI/CD (
- No SSR support (but does support pre-rendering)
SPAonly, no support forMPA- Can't pass env vars at run-time
- only at build time because the
HTML/CSS/JSbundle is static - will need a server (e.g.
Node) to loadHTML& populate placeholders
- only at build time because the
- opinionated (some may say bloated) - may not need most tools / libs
- though ejectable & configurable
- steep learning curve (elaborate config, though well documented)
A custom project setup.