Client-Side Rendering

CSR Workflow:

  1. Browser requests a page like https://example.com.
  2. Browser sends a GET request to the server.
  3. The server sends back a minimal HTML page.
<!DOCTYPE html>
<html>
  <head>
    <title>My App</title>
  </head>
  <body>
    <div id="root"></div>
    <script src="app.js"></script>
  </body>
</html>

// <div id="root"></div> is empty (content will appear here later)

// app.js is the JSfile that contains all logic to render the page.

  1. Browser downloads app.js and executes JS:
    1. Finds the #root element.
    2. Calls a framework like React, Angular, or Vue to create HTML elements.
    3. Populates the elements with data (fetched from an API if needed).
  2. Browser fetching data
  3. Rendering the page
  4. User now sees a fully functional page.

Advantages of CSR

  1. Fast interactions after initial load
  2. Reduced server load