Next.js Discord

Discord Forum

SSR and SSG

Answered
Chinese perch posted this in #help-forum
Open in Discord
Chinese perchOP
Hi, I need a way to build, using the new app folder structure, pages that are static and pages that are SSR but as far as I can see I can't do that in one project, can you please help here? Output: export makes the HTML but what about the SSR ones?
Answered by joulev
you can't do output: export with dynamic rendering
View full answer

50 Replies

Answer
but if you don't do static export, but just deploy on vercel or deploy with next start for example, then you can use both SSG and SSR at the same time yes
Chinese perchOP
so, let's separate a bit, I want to have my html pages put in a CDN and my non-html pages being served by a node server, it this achievable?
@Chinese perch so, let's separate a bit, I want to have my html pages put in a CDN and my non-html pages being served by a node server, it this achievable?
on vercel then i think they do this automatically for you. if you self-host then idt this is easily achievable
Chinese perchOP
on vercel I dont' have that much control or overview on what's happening under the hood, the client might want different behaviors on different routes
Chinese perchOP
@aardani hi
Just curious, why do you need html export if you can afford to have a server that renders the SSR
Chinese perchOP
cuz I don't need SSR for static content
I push my static files somewhere in s3, use cloudfront to expose them and focus on the other parts
I mean just deploy on vercel where you can have both SSR and SSG in one project/deployment. Why not that?
If you dont need SSR for static content then dont use SSR? Why do you ask about SSR?
Chinese perchOP
because companies usually have restrictions on infra choises
so I need SSR for non static stuff like user dashboards
but I also need SSG for static stuff like about the company, who are we.. etc
Ah
Chinese perchOP
and companies have aws in their tech stack.. I can't just tell them.. move to vercel 😦
Yeah no, next's static exports are... well, static. You cant have dynamic rendering on static exports. Use client component instead to dynamically render a page
See more ere
Chinese perchOP
or do a mono-repo :)) and have 2 builds
See this is where im confused
Why 2 builds where you can just do 1
If you can have build that can do SSr it should also able to do SSG
Chinese perchOP
one build does the htmls, the other one does the SSR .next folder that runs on the node server
Why not use the node server to also serve SSG routes
Chinese perchOP
because it costs 😦
Ah
Chinese perchOP
technically you are right.. you already have a server why bother, but the server configs are not the same for these routes
I just got involved with something outside of my experience: cost optimization
Chinese perchOP
so for the static stuff, you might have different site settings, caching strategies, TTLs and other crap to optimize the delivery
If SSR is expensive why not serve client component to clients so that you can have SSG dashboard
Chinese perchOP
while in the server you need WAF, load balancers, DMZ and other crap
well we end up in the CSR is slow, web vitals suffer kind of scenario
But its cheaper to host :>
I assume
Chinese perchOP
yes it is, also SEO suffers
Why do you need SEO on dashboard...
Chinese perchOP
no idea tbh, business people say the darnest things :))
...
No believe me you dont need SEO for dashboard
Chinese perchOP
maybe they want to optimize the search for "cost control" feature
The about me page help page and stuff can get their SEO right but when it comes to dashboard you can use client conponents to serve dynamic data. Its fine, youre fine. Cost is low everybody happy
Chinese perchOP
I do believe you, I'm just the tech guy implementing what the architects and product owners invision, and this is what I'm struggling with
I see
I hope you can make terms with your product owner
Id argue having SSR server is not the most cost effective but im not your product owner :>
Although it is more secure and provides better UX
Chinese perchOP
I had to ask, if it's something doable and I'm not aware of
Right i suppose you already got your answer right?
Chinese perchOP
yup, now I'm just painting the picture for people to understand this is a common example