-
Lately, I've been reading more and more people suggesting to statically render something and then on client make subsequent requests to complete the experience with proper data, when necessary. Basically the Jamstack approach, which makes sense from a conceptual point of view. Thing is, with that approach, I'm failing to see a scenario where doing server side requests for stuff like fetching current user would make sense. How does the Next.js team feels about this? |
Beta Was this translation helpful? Give feedback.
Replies: 24 comments 20 replies
-
Next.js is a hybrid framework. We will be recommending static and static site generation as a default. We already output SSR still makes sense for veeeery large sites, but we are also addressing that with SSG. We will be doing a follow-up RFC once the one above lands to explain that. Thanks for asking! |
Beta Was this translation helpful? Give feedback.
-
Thanks, @rauchg! |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
In my case, I'm building a news site, and SSR is key for SEO and for Open Graph Protocol. If we don't do SSR, our site looks empty for google bots and that's no good for a news site. Doing full SSG won't do because on every article created we'd have to build it again... |
Beta Was this translation helpful? Give feedback.
-
The primary benefit of SSR is SEO and syndication related. Ever tried sharing a SPA link on Whatsapp? The metadata is the same for every page on your site. The real question isnt about SSR but if you'd rather have an active vs static site. Static sites have two critical disadvantages:
For me, it's clearly necessary to have an active server to accompany my apps and once I have that SSR is easy. |
Beta Was this translation helpful? Give feedback.
-
Amazon is server side rendered. |
Beta Was this translation helpful? Give feedback.
-
In general, SSR has better compatibility. Imagine you built a SPA in ionic stencil, then someone come to your site with Android 4.4 or below, they see a blank page (or a splash screen, loading forever). |
Beta Was this translation helpful? Give feedback.
-
I tried to write that down as a blog post earlier. You might want to check it out: https://olavihaapala.fi/2019/12/11/we-have-gone-full-circe.html |
Beta Was this translation helpful? Give feedback.
-
Not necessarily, more on this soon 💯 |
Beta Was this translation helpful? Give feedback.
-
I feel like the missing link we have here is to have a system in place which prepares static pages on demand, with some simple way to trigger rebuilds at runtime, without the need to build a complex CI around it. So basically what some classic content management systems could do a decade ago, although not decoupled back then. E.g. I have a list of blog posts, and some page that displays the last 20 of them. Now there could be some trigger to tell nextjs: Rebuild that page, or even better but unsure if feasible, rerender just down from the tree at the point of the changed data of some refetched query. I could think of different triggers here which all might have their usecase:
|
Beta Was this translation helpful? Give feedback.
-
So basically WordPress? 🤔 All these fancy modern technologies are cool, but it seems like we keep revisiting good old ideas :) |
Beta Was this translation helpful? Give feedback.
-
Yes For example, that’s what I meant when I said
However it doesn’t feel like a step backwards for me and the only similarity here is page caching: We still would have all the advantages of modern technologies, could still use dynamic stuff like isomorphic rendering and have things decoupled compared to classic monoliths. But, while probably simple, I would not favor a „Cache on first visit“ approach. Out of 1000 visitors, the first should have a fast page load aswell. Also I think this wouldn‘t cover how to do invalidations: I did a quick lookup on the plugin you mentioned, it seems like it only does this based on a fixed expiry time. This part should allow for as much flexibility as possible, with expiry time just being one of them. The only real disadvantage I see is that things could break during runtime which would else be catched during build. However, the same would apply on any other data fetched on the client or during SSR. I don’t want to go too far beyond the scope of nextjs, but in such cases there could even be defined fallback behaviors, like to keep the existing render that succeeded, or additional hooks that could be executed on a finished page build before it becomes active to do testing during runtime. For sure this would reach a certain complexity where it might make sense again to have a CI in place specific to the usecase instead of having the next monolith, but I think there is a golden middle here which is more than the current functionality. The current SSR vs CSR vs SSG just feels like a dead end to me and I don‘t get why I should chose between options that all have their disadvantages. The nextjs hybrid approach to have this on a per page basis also doesn‘t solve it, as those pages requiring fresh data would still have way less performance than they ideally could. |
Beta Was this translation helpful? Give feedback.
-
I agree about WordPress having some advantages. The downside however is that WordPress is not portable and is slow and complicated to work with (old tech) Have you guys seen https://factor.dev? ^^ that is the WordPress approach w modern tech. |
Beta Was this translation helpful? Give feedback.
-
Yeah I really think we should not focus on wordpress advantages any further here, as this is a nextjs discussion and the technical stacks are completely different. |
Beta Was this translation helpful? Give feedback.
-
Factor is easily cached, authentication is done in the client so the source is same for all requests. it would be easy to add static stuff but that's a competitive space and a solved problem. Factor's advantages come from having an active server which works behind the scenes to help you avoid using 100 apis and SaaS tools to make a decent app. |
Beta Was this translation helpful? Give feedback.
-
You can also pre-cache commonly-accessed pages before they're visited. Some things are just not precacheable though, for example search results.
You can configure it to cache indefinitely and only clear the cache when changes are made (eg. new posts are published)
If you want something very fast you'd likely need to look at something like Hugo. IMO JS apps are actually more complicated than PHP apps... dependency management with npm has a lot more edge cases compared to Composer.
True, I agree, but on the other hand it's useful to compare advantages and disadvantages of alternative solutions in order to build something that's the best of both worlds. There's also more modern hybrid approaches with WordPress where you use it as a 'headless' CMS. All the post management is done in WordPress, and the actual site is build using a static site generator that uses the WordPress API as input. You get some of the advantages of WordPress (great post management experience particularly for non-technical users, not having to use/deploy Node.js) along with some of the benefits of a static site generator (fast for users, more secure as it's just serving plain HTML). That's worth considering when comparing different systems. |
Beta Was this translation helpful? Give feedback.
-
For me, working with WordPress is like nails on a chalkboard. I just can't bring myself to spend hours and hours learning and debugging obsolete tech (my opinion). |
Beta Was this translation helpful? Give feedback.
-
SSR is still needed if your content changes frequently, like a classifieds website. And you need SEO also. |
Beta Was this translation helpful? Give feedback.
-
Reported the spam bot. |
Beta Was this translation helpful? Give feedback.
-
For small to medium websites, SSG is great. However, SSR is definitely necessary since we have millions of dynamic pages. We can't afford it to be compiled during build and we need realtime update for those pages. |
Beta Was this translation helpful? Give feedback.
-
As far as I can see, one needs SSR when wanting to release features to only some of one's users, for example only logged in users should get the new features, or only 10% of the users, etc. We are using this all the time to make sure we make stuff that users actually think is nice. The problem with this is of course not being able to take advantage of caching of almost static pages, i.e. it will be a small number of variants for each page which would be easy to cache. Does anybody have a good solution in Next.js for this use case? |
Beta Was this translation helpful? Give feedback.
-
Actually you don't need SSR for this. You can expose data for these features behind an API and fetch data from the client side. I don't think static pages/regeneration is a solution for user specific pages. I'd like to share more feedback, if you give more information. May be in a different thread. |
Beta Was this translation helpful? Give feedback.
-
Let me know if I get it right: For "public-first" websites (blog, e-commerce)
For "private-first" websites (Software as a Service, administration interface)Private apps have been bugging me for a while but I think I get it better now:
Specifically, one might be tempted to systematically use SSR for private apps, because technically the render is always depending on the current logged user (so the current request cookies or auth header). Even if you load the data later, client-side, you still need to check if the user has access to the page. But using Instead, using a simple, dedicated server for auth check, and then considering the private app as it is was public seems smarter and simpler. In all those scenarios, using Maybe it could be doable using just Next, but I think this would need to be able to setup a kind of middleware that runs only when the server is running but not during SSG (without a custom server). |
Beta Was this translation helpful? Give feedback.
-
Hey guys, could somebody give me their point of view about: https://github.com/theninthsky/client-side-rendering#ssr-disadvantages. This case study has some good points about CSR, SSR, and SSG. |
Beta Was this translation helpful? Give feedback.
Next.js is a hybrid framework. We will be recommending static and static site generation as a default.
We already output
.html
files if you don't usegetInitialProps
and thegetStaticProps
andgetStaticPaths
methods (#9524) allow you to move fromgetInitialProps
easily over to production-grade static site generation.SSR still makes sense for veeeery large sites, but we are also addressing that with SSG. We will be doing a follow-up RFC once the one above lands to explain that.
Thanks for asking!