DEV Community

Cover image for Next.js SSR vs CSR vs SSG which is best to use and when to use?
Athashri Keny
Athashri Keny

Posted on

Next.js SSR vs CSR vs SSG which is best to use and when to use?

These names feels confusing first, but when you understood it deeply its much easier than you think!

SSR (Server-Side Rendering) ,CSR(client Side Rendering) , SSG(Static Side Generation). These all are web page rendering methods

Let's first dive in
SSR: In SSR(Server-Side rendering) server renders the full html for every request and sends it to the browser. because it is rendered on server not in the client side ie in Brower the page loads quickly.

pros: SSR is great when you want a good SEO rating on your webpage. For eg news websites , landing pages . but there is a catch you need to have a good server which is capable of handling a ton of requests.

Cons: Due to heavy load on server these can can cost you a good amount of server bills.

CSR: (client side rendering) In CSR, the server sends a minimal HTML shell to the browser. JavaScript then runs in the browser to fetch data and render the content dynamically.
After the page has been loaded for the first time, navigating to other pages is typically faster because it doesn't require a full page reload - only the necessary data is fetched via API calls, and JavaScript updates the DOM dynamically.

pros: CSR is great if your data changes consistently on a page. and you don't care about SEO at all. CSR can be used in fetching user data , a live score match etc. and server load is less.

Cons: Slow initial load. your app takes a noticeable amount of time to load user can feel this.

SSG: In SSG (Static Site Generation), HTML pages are pre-built at build time (during deployment), not at runtime. These pre-rendered HTML files are served to users on every request, without needing to generate them again.

pros: SSG offers a fast-performance , excellent seo, reduces server load (this can be lead to lower server bills).

Cons: All pages are built at the time of the build so this can cause a longer built time, and the content is only updated when site is build again.

Final Thoughts
Choose based on your needs:
Need SEO + real-time data? → SSR
Building an interactive app? → CSR
Content rarely changes? → SSG

Thanks for reading i hoped it helped you!

Top comments (0)