Client-Side Rendering (CSR)
Learn about client-side rendering techniques and their advantages.
A standard React app is rendered once the JavaScript bundle has been transferred from the server to the client. If we’re familiar with
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8" /><link rel="icon" href="%PUBLIC_URL%/favicon.ico" /><meta name="viewport" content="width=device-width, initial-scale=1" /><meta name="theme-color" content="#000000" /><meta name="description" content="Web site created using create-react-app" /><link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /><link rel="manifest" href="%PUBLIC_URL%/manifest.json" /><title>React App</title></head><body><noscript>We need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
As we can see, we can only find one div
inside the body tag: <div id="root"></div>
. During the build phase, create-react-app
will inject the compiled JavaScript and CSS files into this HTML page and use the root
div as a target container for rendering the whole application.
That means that once we publish this page to any hosting provider (Vercel, Netlify, Google Cloud, AWS, etc.), the first time we call the desired URL, our browser will first render the preceding HTML. Then, following the script
and link
tags contained in the preceding markup (injected by CRA at build time), the browser will render the whole application, ...