Have you ever found yourself pulling your hair out trying to understand SSR and CSR? Maybe you’ve been asked in an interview to explain SSR and CSR, their differences, and when to use each one. Or perhaps you’ve heard about Hybrid rendering, which combines both CSR and SSR, and you’re not quite sure what that means. Don’t worry—let’s dive into these concepts and discuss them in detail.
But before moving to that we should first know the steps involved in getting a web application from development to being used by users.
Process
- Build: Prepare the code by compiling, bundling and optimizing it.
- Server: Host the prepared code and serve it to users.
- Execution: The user’s browser load and renders the application making it interactive.
Now that you have understand the process of web application from development to users let’s dive into our topic.
SSR(Server Side Rendering)
Server side rendering means rendering web pages on the server and sending fully rendered HTML to client.
How it works:
- As a user you request a web page.
- The server process the request and generates the HTML content.
- The server will then send a fully rendered HTML to your browser.
- Browser will display it’s HTML content to you.
That’s all about SSR and working of SSR. Now that you how it works let’s discuss it’s pros and cons:
Pros
- Faster initial load: Now that you know HTML is being rendered on the server side, your browser can display the content as quickly as it receives it.
- SEO: Search engines can easily crawl and index the fully rendered HTML.
- Low-end Devices Friendly: Better performance on low end devices as it requires minimal processing on the client’s side.
Cons
- Server load: It increases the server load as most of it’s processing is done on server side.
- Slow Interaction: After the initial load further Interaction will require more communication with the server.
CSR(Client Side Rendering)
Client side rendering means rendering web pages on the browser side using Javascript.
How it works:
- As a user you request a web page.
- The server sends a minimal HTML file along with JS to the client.
- The browser downloads and executes the JS and generates the HTML dynamically.
- Browser will display content to you.
Now that you how it works let’s discuss it’s pros and cons:
Pros
- Better Interactivity: Faster interaction as it processing happens at client side.
- Server load: It reduces server load as server sends static files.
- User experience: User experience is better as dynamic content updates happen without page reloads.
Cons
- Slower initial load: As processing happens on client side it’s obvious that it will take longer time.
- SEO: Seo challenges will be there as Search engines might have difficulty indexing content that is dynamically rendered.
- Usage: Resource usage is generally high as processing happens on your(client’s) device.
Both SSR and CSR have their use cases, and often today’s modern applications use a combination of both (called hybrid rendering) to leverage the benefits of each approach.
1 Comment
1