Our Tech Journal
  • Introduction
  • Overview
    • Introduction
  • Javascript
    • JS Runtime, Env Context, Scopes, Hoisting & Execution Cycle, var/let/const, this
    • Javascript Runtime Env
      • Event loops
    • What are WebVitals
    • Module Patterns in JS - CommonJS, AMD and ES6 classes
    • Lexical Environment in JS
    • var vs let/const
    • Temporal Dead Zone (TDZ)
    • Execution Context
    • 'this' keyword
    • undefined value in JS
    • Function expressions vs Function statements
    • Javascript Code Execution
    • Closures
    • JS : Object Oriented Programming
    • Prototypal Inheritance
      • Creating Object in Javascript
    • NaN
    • Objects
      • Ways to create
      • ways to check if Object is empty
      • Object's own properties
    • use strict mode
    • typeof vs instanceof
    • Promise
    • localStorage and SessionStorage
    • Event handlers
    • Event bubbling
    • Event Delegation
    • XHR Request
    • Promise Error: Catch vs Error Function in Then
    • Immutability
    • Useful Code samples
    • window, document, screen
    • window.innerheight, outer height, screen.height
    • JS Design Patters
    • Interview Questions
    • Encapsulation - Module Patterns in JS
    • Redesigning services using Entity framework approach
  • JS Functions
    • JS Array - Slice vs Splice
  • PWA
    • What is PWA
  • ES6
    • Sets
    • Maps
    • spread vs destructure operator
  • Web
    • http / https
    • CORS
    • CSRF
    • XSS Attack
    • What is SPA
    • Semantic Elements in HTML
  • Angular 4
    • Angular vs React
    • Change Detection
    • Lazy Loading of modules
    • Preloading
    • AOT Compilation
    • Route Guards
    • Shared Modules
    • Tree Shaking
    • LifeCycle Hooks
    • ngRx
    • Observables
    • Observable vs Subject
      • BehaviorSubject
    • Observables vs Promises
    • Builtin Directives
      • Temp
      • Structural Directives
        • ngForTemp
        • ngSwitch
        • ngFor
        • ngIf
      • Attribute Directives
        • temp
        • ngClass
        • ngStyle
    • Routing
      • Routing in Angular
      • Setting up basic routing
      • routerLink and routerLinkActive
      • router.navigate and ActivatedRoute
      • Route Params as Observables
      • redirectTo
      • relativeTo
      • pathMatch
      • ActivatedRoute
      • Routing in Angular
      • Passing Data with Route
      • Route Parameters
    • Intercept HTTP request
    • Custom Directives
    • Communication between components
    • Angular Modules
    • Reactive Forms
    • Unit Testing
      • TestBed and component fixture
      • Testing HttpClient requests
      • Testing fakeAsync
  • GraphQL
    • Introduction
    • Server
    • Client Side
    • GraphQL in Angular
    • Queries
      • temp
      • query with parameters
      • aliases
      • fragments
      • @include directive
      • @skip directive
      • variables
      • Inline Fragments
  • CSS
    • What is Box model?
    • display: block, inline or inline-block
    • CSS Selector: Combinators
    • CSS Pseudo-classes
    • CSS Pseudo-elements
    • CSS3 Filter
    • CSS3 Transitions
    • Media Queries
    • Flex vs Grid
    • CSS 3 Grids
    • What is Flexbox?
    • position: relative vs absolute
  • SASS
    • Mixins
    • Lists
    • Maps
  • RxJS
    • throttle vs debounceTime
    • distinctUnitChange
    • reduce vs scan
  • Typescript
    • Typeguards
    • Pattern Matching with Typescript
    • TS Decorators
    • Using LINQ in TS
  • NodeJS
    • NodeJS Security Checklist
    • What is Node.js
  • REACT
    • React - VDOM - Under the hood
    • Synthetic events in React
    • Routing - React Router 4
    • React Custom hook
    • Higher-Order Component
    • REDUX
    • Redux Thunk vs Redux Saga
    • forceUpdate()
    • Storing Data in React
    • Error Handling
    • React Context
    • How React-Native works
    • refs
    • Server-side Rendering
    • Jest setup file
    • React-test-renderer
    • Lifecycle
    • React Testing Library
    • React Query
  • JWT
    • What is JWT and How it works
Powered by GitBook
On this page
  • Why Server-side Rendering is needed
  • When to use server-side rendering
  • When to use client-side rendering
  1. REACT

Server-side Rendering

PreviousrefsNextJest setup file

Last updated 2 years ago

= ability of a Javascript app on the server side as well

Why Server-side Rendering is needed

- for search engines to index / find your web pages

- for faster first page load-time

- to allow people to share a page of your site via email or on social platforms

With no Server-side rendering, Server would just send the initial HTML along with the bundled script to the browser and then browser would have to compile(interpret) the whole script (including the framework logic) to render the page, this may take long initial rendering time

(SSR for a very large, resource-intensive application on a heavily-loaded server may again slow down the initial rendering )

You can set up SSR using node tools like express or framework like next.js

After Setting up Express app to render your react app's index.html

in you React app app, replace the ReactDOM.render() with ReactDOM.hydrate()

ReactDOM.render(<App />, document.getElementById('root'))

to

ReactDOM.hydrate(<App />, document.getElementById('root'))

and then there is some more setup involved

check this out

Server-side pros:

  1. Search engines can crawl the site for better SEO.

  2. The initial page load is faster.

  3. Great for static sites.

Server-side cons:

  1. Frequent server requests.

  2. An overall slow page rendering.

  3. Full page reloads.

  4. Non-rich site interactions.

Client-side pros:

  1. Rich site interactions

  2. Fast website rendering after the initial load.

  3. Great for web applications.

  4. Robust selection of JavaScript libraries.

Client-side cons:

  1. Low SEO if not implemented correctly.

  2. Initial load might require more time.

  3. In most cases, requires an external library.

Now that you’re aware of the pros and cons of each approach, let’s take a look at ideal scenarios for their implementation.

When to use server-side rendering

  • An application has very simple UI with fewer pages/features

  • An application has less dynamic data

  • Read preference of the site is more than write

  • The focus is not on rich site and has few users

When to use client-side rendering

  • An application has very complex UI with many pages/features

  • An application has large and dynamic data

  • Write preference of the site is more than reading

  • The focus is on rich site and a huge number of users

In a nutshell, server-side rendering is like receiving a pre-assembled toy train set whereas client-side rendering is like receiving a dismantled one that you need to assemble yourself. You have to decide whether you’d like to play with a pre-assembled one or prefer assembling it just the way you want it.

https://flaviocopes.com/react-server-side-rendering/
https://www.clariontech.com/blog/server-side-rendering-vs.-client-side-rendering