Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSR vs SSR vs Pre-render, which one should I choose?

Currently, my project has two parts, one is before login, and one is after login. 

What I want to achieve is, before login needs to be fast and SEO friendly, should I choose pre-render or SSR?

And after login, we can choose CSR (so the client is able to wait for the page to load).

Alternatively, can I do two CSRs, one for before login (fast load), and once client logged in, by JWT token, redirect to the after login CSR page? 

Thanks

like image 596
KeepLearning Avatar asked Sep 26 '19 00:09

KeepLearning


People also ask

Which one is better SSR or CSR?

One of the main arguments for why (though CSR is making significant strides in that direction which we'll explore in more detail later), is that SSR has traditionally been the better choice in the context of search engine optimisation (SEO) because SSR pages are more accessible to search engine bots and crawlers.

Why SSR is faster than CSR?

SSR means there is no need for loaders or spinners for the initial load. This means that, generally speaking, SSR will outperform CSR. SSR apps break JavaScript and CSS into chunks, optimize assets, and render pages on the server before serving to the client browser, resulting in a faster initial load time.

Which is better server-side rendering or client-side rendering?

Between the two options, server-side rendering is better for SEO than client-side rendering. This is because server-side rendering can speed up page load times, which not only improves the user experience, but can help your site rank better in Google search results.

When should I use SSR?

When to use SSR? SSR is recommended for apps in which you have to pre-render frequently updated data from external sources. This technique is especially recommended when the data cannot be statically generated before a user request takes place, and at the same time needs to be available to search engines.


2 Answers

For pages that need to be crawled, most probably CSR is not an option. The question then becomes whether you choose to pre-render or SSR. The answer to that is that it depends.

Is the SEO content static, or does it depends on other some backend API response at a given time?

If it's static, pre-render should be enough for you. But if it depends on other APIs, the content could change during runtime, and you would have to do true SSR to accommodate that. SSR is more resource intensive on the server though.

As for the after login part, because it probably shouldn't be crawled by bots anyway, it is okay to do CSR for all the logged in pages. CSR alone doesn't mean you will have a significantly faster initial load though, there is a lot of factor to consider such as the HTML document size, network trip latency, the response time of the other services your own service is depending on, etc. BUT, along with using a service worker and using the app-shell model, CSR should almost always be faster compared to SSR. I would recommend looking into that to improve CSR speed. Link

like image 117
Jackyef Avatar answered Oct 23 '22 06:10

Jackyef


It depends.

if SEO is irrelevant — e.g. an app that lives behind a login screen — then CSR is fine and you just need something like ReactJS

If you need a good SEO:

a) If you can predict the content to generate it in build time (eg: a blog), then you need SSG (static content created on build time) and should choose something like Gatsby or NextJS

b) If you can’t predict the content/possible request (eg: a search page), the server will need to generate the pages on demand, so you need dynamic SSR (content created on user access time) and should choose something like NextJS.

Note: NextJS allows you to selectively mix in the same project the 3 main rendering forms. For that reason is the best option if you need SEO.

like image 44
Juanma Menendez Avatar answered Oct 23 '22 06:10

Juanma Menendez