The nice thing is on a current project I found there was one view where SSR made my life a lot easier and since everything was in place for it all I had to do was chuck in an extra function.
Some of my colleagues are pushing hard for it. It seems like nice tech, but when you build an enterprise web app behind a login page, I see no need for server side rendering.
Our users open up the app in the morning, work on it a whole day, and do the same thing the next day.
I absolutely see no point in trying to optimize this with server side rendering.
But it seems some front-enders want to use the latest best thing, even when it's not really necessary.
But what do you do? Do you make these developers unhappy because they are not using the latest cool thing, or do you make them happy but end up with an inferior solution?
Oh boy, these youngsters... ;)
If you're using React, Next.js is a pretty excellent choice for pretty much any website.
Appeal to Tradition is just as much a logical fallacy as Appeal to Novelty.
Edit: next.js is a web server, right? Because how else can it do SSR?
Edit: Unintentional sarcastic reply from my side, it was a good question.
In other words: what is the benefit of next.js when you only do CSR?
If you use Next.js only for CSR, as I'm sure most people do, the benefits are great defaults, easy upgrades, fantastic routing, page prefetching, and easy upgrading to any of the other rendering modes if you ever need them.
You don't run any kind of server if you just use CSR - you bundle your code and push it to anywhere you'd push your normal React SPA (CDN, Vercel, Netlify, etc). I you decide you need to server side render or pre render a page, you can of course run a full node server - but the far easier route is to use the Vercel/Netlify lambda functions(which work out of the box with Next).
I find thinking of Next pages as separate little apps composing the same layout component to be far more maintainable than the more traditional SPA single layout swapping the contents to simulate a page transition.
Further frameworks can be deceptive by making complex problem sets seem easy to deal with but later involve complex refactoring over time as the problem set is better understood and evidently less trivial for your organizations particular wants and needs.
These problems aren't highlighting any implicit fault of next.js. Just predicting incorrect ways developers will use it and suffer from. There is an argument to be made these problems would be made less severe if they were approached from the ground up without a framework and what opinions it brings.
Also FWIW I like next.js the project a lot. Hopefully Vercel proves a good steward for it.
Such web apps can be downloaded to the client the first time you open the page, and after that (basically every day), caching strategy makes sure you don't have to download that thing again.
Which means you only need to transfer pure data at that point, and you can have a very responsive web page.
SSR rendering on the other hand, you will get some kind of PHP website (OK, this is exaggerated, but you get the point). Requests go back to the server, and the server renders the page. Totally ludicrous.
SSR: for landing pages, SEO optimization, showing the same page to a lot of users, etc.
CSR: for heavy apps that you use regularly, basically "real" applications, not web pages.
NextJS only renders (or gets the static HTML) and sends you the HTML for the first page you navigate to. When you click a link on that page, it just sends you the data (and JS if needed).
Most of the time the app is either large and sprawling, updated frequently, or XHR fetches are written in an inefficient way. All of these nullify the benefits from the model of having cached application code. For example if you're waiting for your JS app to initialise, then fetching XHR in a serial way you're probably slower than an SSR page that is sending a data blob down inline.
I'd say SSR is a good rule of thumb, and the few people who build SPAs who can make use of this will know when to break that rule.
> SSR rendering on the other hand... Requests go back to the server... Totally ludicrous.
For Next.js, this description of routing and rendering is “Totally” incorrect. I don’t know about other SSR frameworks (except maybe PHP, which does actually work as the parent comment describes), but with Next.js, you get SSR on first page load and CSR on subsequent clicks.
Thats the whole point of next/router and the <Link> component. Hovering a <Link> will download (“pre-load”) the tiny JS file required to render the next page. Clicking it will trigger client side rendering, without any new server side page load.
The complexity that causes this kind of misunderstanding is the best argument against SSR.
I'm very confused by this statement. Maybe I'm just being slow. If you want to fetch data from the db before returning html, then SSR is exactly what you want.
Example: Next deployed to AWS (metered bandwidth), with DataSource deployed to colocation (unmetered bandwidth). Page fetches 1GB CSV from DataSource in order to render an HTML Table. In this case, you likely prefer the client to fetch directly from DataSource and render the HTML table during CSR. An exception might be if you care about the table for SEO purposes (e.g. structured data) – but in that case, you should find a way to fetch the first 10 rows instead of 1GB.
It's a fairly niche use-case, though, and it's easy to opt out of SSR for specific code/requests (check if window is defined) or pages (use Next getServerProps vs. getStaticProps).
As an aside... this convoluted scenario highlights one criticism I have with Next.js: It is NOT a friendly mental model for junior engineers. You cannot write a robust Next app without a thorough understanding of the HTTP request lifecycle, network architectures, closures, database/HTTP pools, caching, cookies, etc. If you stay within the lines, you can avoid worrying about most of this stuff, but it's impossible to fully grok Next without a strong background in web fundamentals. If I were advising a beginner on the best stack for practicing React, I would suggest starting with create-react-app, even though I think Next is ultimately the best production framework.
If you don't show it, you don't need to query it.
Some would argue that React in general isn't a good fit for low-powered devices with a slow connection, because of its bundle size, long first input delay and a rather high cost of heavy javascript usage during re-rendering.
You might think you have control over the environment someone accesses the app in, but you don't, at least not entirely, and why not just make it as easy as possible to get their work done however they want?
Of course, this doesn't make your thing automatically better all around. That's a design and implementation problem. But you do potentially help everyone by starting at the bottom
That's two languages: javascript and php. Many frontend developers would prefer to just work with one — javascript.
99% of all js project would have been better with an old school framework (Rails/Symfony/Django/laravel, and any other framework I forgot the name)
I so agree that next is not the ultimate answer. Still waiting for the absolute best of both worlds.
Write SSR, but have the ability to render partials and swap html chunks into the DOM directly rather than running json through a CSR library.
You still get client originated events (user clicks a button) or server originated events, e.g. server wants to proactively push a change - at least for liveview and htmx.