Server-side rendering (SSR) is a web development technique that generates a webpage's HTML on the server before sending it to the user's browser.
Unlike client-side rendering, where JavaScript builds much of the page in the browser, SSR delivers HTML containing the page's initial content.
SSR is commonly used in e-commerce websites, news platforms, and search engine-friendly web applications.
A typical SSR process includes:
Hydration is common in SSR frameworks but is not required for every server-rendered website.
Both techniques display webpages, but they generate HTML differently.
| Feature | SSR | CSR |
|---|---|---|
| Initial HTML | Generated on the server | Primarily generated in the browser |
| Initial content | Often available immediately in HTML | May require JavaScript execution |
| Server workload | Higher during rendering | Often lower |
| SEO | Easier content discovery | May require additional rendering |
| Interactivity | May require hydration | Managed by browser JavaScript |
Modern applications can combine SSR and CSR to balance performance and interactivity.
Server-side rendering and static site generation (SSG) both deliver pre-rendered HTML.
SSR is useful for frequently changing or personalized content, while SSG works well for pages that change less often.
SSR websites often provide meaningful content directly in their initial HTML responses.
This can simplify web scraping because developers may extract information using HTTP requests and HTML parsers without launching a browser.
However, some SSR applications still load additional information through JavaScript or APIs.
The appropriate scraping method depends on how the website delivers the required content.
Suppose an online store uses SSR to display product details.
When a visitor requests a product page, the server generates HTML such as:
<div class="product">
<h1>Wireless Mouse</h1>
<p class="price">$29.99</p>
<p>In Stock</p>
</div>
The browser receives this content immediately in the HTML response.
A web scraping application can also parse the response to extract the product name, price, and availability without executing JavaScript, provided the information is included in the server-rendered HTML.
Server-side rendering (SSR) generates webpage HTML on the server before delivering it to the browser.
It can improve initial content visibility, support SEO, and simplify data extraction. However, SSR requires careful management of server performance, caching, and client-side interactivity.