Rendering Methods
Last updated
Was this helpful?
Last updated
Was this helpful?
Initially, the page of the html is empty
Until the javascript finished download, the screen will be rendered based javascript code
Finally, the page becomes interactive
The user interactivity will be better, as the data fetched can be determined by user
Also, after loading, the page becomes interactive
It is better to fetch large amount of data, as the data can be fetched separately, but not once time finished
The loading of navigating the page will be faster
low SEO
The initial loading is slow, especially when the network is slow, as the javascript file need to be waited for downloading
The html with content will be render in server
Therefore, the content page can be viewed at this moment, but still not interactive
After javascript file is downloaded, the page becomes interactive
The initial loading is faster, as not need to wait javascript file be downloaded
Better SEO
When the page is changed, the page content with html need to render again
Even the page is viewable, but still not interactive , which may affect the user experience
The structure will be more complex for react
If the page containing large amount of data, it will be nightmare to render the whole of the page in once time
If the user request is frequently made , it will slow down the rendering from server, as the page is rendered for each user request
Initially, the page will rendered from the server
After javascript finished downloading, the react application will be hydrated and turn it into single page application. So that, when the page is changed , the whole of the page do not be rendered from server comparing with traditional SSR like jsp, php
Better for the page with large amount of data and high interactivity
Better for the static page or page with fewer data
The static page will be pre-rendered during build time
Therefore, the initial static page will be shown when user request comes in
The page will be rendered in build time for SSG and the content is always the same
The page will be rendered in run time for SSR and the content in each rendering can be different for each user request
React Server Components are always rendered on the server
If the props of server component is updated, the re-rendering will also be conducted on server-side
Since the logic and dependencies is on server side, it will reduce the bundle size of javascript downloaded on the browser
The on click, on change , ... and react hook cannot be used
Commonly used on the component that mainly for visualization but not interaction, e.g: to do list
It is not allowed to import a Server Component into a Client Component since client components are rendered after server components
But it is allowed to pass Server Components to Client Components as Props. Therefore, <ClientComponent>
and <ServerComponent>
are decoupled and can be rendered independently. In this case, the child <ServerComponent>
can be rendered on the server, well before <ClientComponent>
is rendered on the client.
the life of a page using RSC always starts at the server, in response to some API call to render a React component. This βrootβ component is always a server component, which may render other server or client components
The end goal of server-side is to render the initial root server component into a tree of base html tags and client component βplaceholdersβ which contains the path of client component function to form a hybrid tree of server and client components. We can then serialize this tree, send it to the browser in JSON
The browser receives the JSON output from the server, and now must start reconstructing the React tree to be rendered in the browser to replace the client placeholder into real client component function
SSR apps are about the initial page load, the client is likely to end up downloading all your dependencies as they explore your application
For SC, those dependencies will always be only on the server since those React Server Components are not shipped to the front-end until they have been rendered.
Just like what happens with SSR, the server is going to fetch the data from the backend. But we donβt need to wait till we get the data from the backend. There are parts of the app like the header and the side panel that we can render without the data. So, the server renders these components and streams them to the browser.
SSR / CSR / SSG 's main concern is about the page
Server Component / Client Component main concern is about the component
Since a page can be consisted of multiple components, so the page can be the mixture of Server rendering , Static generation and client side rendering if using latest approach