Server-Side Rendering (aka SSR), is a web development technique where the server renders the whole HTML webpage and sends it to the browser. In simpler terms, instead of having your browser build the page dynamically with JavaScript (like in Client Side Rendering, or CSR we do in ReactJS), the server does most of the heavy lifting and delivers a fully-formed HTML page to the browser just like static websites page works.
When a user requests a webpage, here’s what happens in an SSR setup:
Request to Server: The user's browser sends a request to the web server with the URL.
Server Generates HTML: The server processes the request, runs any required backend logic, pulls data from databases or APIs, and generates the fully-fledged HTML page as it is to be shown on the browser.
Send to Client: The server sends the pre-rendered HTML as the request response to the client’s browser.
Browser Renders Page: The browser displays the page almost instantly just like static pages, since it receives a fully-formed HTML document and no other processing is required unlike in ReactJS where the application hits APIs to populate data, and converts the final page.
Now, why should you even care about SSR? Here are the main benefits:
Faster Initial Load Time: With SSR, the browser gets a fully-formed HTML page, which means the user sees content faster, especially for users with slower connections or with less powerful devices. This is very crucial for retaining visitors and reducing the bounce rates of the users.
SEO Benefits: Search engines like Google love SSR because it provides complete HTML content at the time of crawling and not a screen with a loader. This makes it easier for search engines to index the content of your pages and improves performance, which can improve your website’s ranking.
Better Social Sharing: SSR makes sharing your content on social media smoother. Social platforms pull metadata (like the title, description, and images) directly from your server-rendered HTML, ensuring that your shared links look great every time.
Improved Accessibility: Server-side rendering can enhance accessibility by delivering fully-formed content that can be easily interpreted by screen readers and other assistive technologies.
So, where does SSR fit in the rendering group, and how does it compare with other rendering methods?
Client Side Rendering (CSR): CSR is when JavaScript on the client’s side (browser) does all the work of building the webpage. It’s more dynamic and interactive but can result in slower initial load times because of the processing on clients and less SEO-friendly pages since search engines might struggle to index dynamically generated content and slower to render. It is mostly used for interactive applications where SEO is not required, like Gmail.
Static Site Generation (SSG): SSG cook the HTML files for all pages at the time of building and not at the time of request. It is the fastest of the options and it’s great for sites with mostly static content that doesn’t change often, but not so much for dynamic content like user-specific dashboards or real-time data. People use a combination of SSG and CSR, where the static data comes directly as an HTML page while the other items like user comments get populated on the client side.
Server Side Rendering (SSR): SSR is like best of both worlds. It offers the benefits of faster initial load times and SEO-friendliness, like SSG, but retains the flexibility to serve dynamic content like CSR. The downside? It requires more server resources and can be complex to implement at scale and at every request the processing happens on the backend.
Server Side Rendering is a powerful tool in the web developer's toolkit, providing a great balance between performance, SEO, and dynamic content delivery. It’s not always the right choice—if your site is small and mostly static, SSR could be overkill—but for many modern websites, it’s an invaluable strategy for ensuring users have a fast, smooth experience. IMO, if more than 60% of your website is static and the rest is interactive then you should go for SSR/SSG and start calling it a website, but if more than 60% of your application is interactive, like Gmail, then SSR is totally not the right choice.