Can you deploy a Next.JS to CloudFlare Pages thats using both SSR and static SSG?

From what I can find out from the docs, CloudFlare offers two routes to deploy Next.Js, either full-stack or static. For our requirements we have 80% of the pages will be static but 20% will require some API and real-time dynamic content and both would need to be on the same domain / routes. Could anyone help and confirm if it's possible to deploy on static and use workers for the APi/Dynamic pages on the same deployment?
29 Replies
Hello, I’m Allie!
Sort of? IIRC you can just not add SSR features to a page when using #next-on-pages, though as I understand it, you will still be billed for functions invocations
1luv
1luvOP8mo ago
Thanks @HardlyWorkin' but you deploy as a static-deployment ?
Hello, I’m Allie!
No, you would deploy the entire thing as an SSR deployment, with some components that don't actually require SSR
1luv
1luvOP8mo ago
Don't you then loose all the static site benefits? It's then just a normal full-stack deployment
Hello, I’m Allie!
Which benefits?
1luv
1luvOP8mo ago
Static pages are all pre-generated there are no requests for anything, they are cached so can be served by CDN as static files.
Hello, I’m Allie!
I should note that even with SSR, the pages are still served from the CDN The only downside is that requests are billed
1luv
1luvOP8mo ago
but each time they are requested the server is generating the content.
Hello, I’m Allie!
Yes, but that server is also the CDN Every CDN server in the Cloudflare Fleet also runs Pages
1luv
1luvOP8mo ago
Then it's just a normal SSR Next.js application, there is no concept of a static files. So in essence you cannot run a mixed deployment. It's either fully static or a normal deployment with SSR.
James
James8mo ago
You can have routes that are pre-rendered at built time instead of being SSR'd at request-time just dont opt them into the edge runtime and it will try to prerender them
1luv
1luvOP8mo ago
👌 How do you specify which routes are pre-rendered?
Hello, I’m Allie!
Those still invoke Functions tho right?
James
James8mo ago
Just don't opt the route into the edge runtime. Only routes opted into the edge runtime can do SSR on Pages Yes. Every request (prerendered or SSR route) will result in a worker invocation because it goes through the routing system
thanhle
thanhle8mo ago
Dont add the export const runtime = edge to that route, then is is static generated at build time.
James
James8mo ago
yes
1luv
1luvOP8mo ago
So under the Pro tier, you get unlimited static requests, but none of these would be seen as "static requests" ?
Hello, I’m Allie!
Even on the Free Tier, you get free unlimited static requests. Though as you pointed out, static pages would still be billed, since they are still served by the NextJS router
1luv
1luvOP8mo ago
So how’s this deployment billed if some routes are static and some SSR?
Hello, I’m Allie!
Every request(other than requests for assets) are billed
1luv
1luvOP8mo ago
But if it were pure static deployment it wouldn’t be right?
Hello, I’m Allie!
That is correct
1luv
1luvOP8mo ago
That’s a shame, CloudFlare seemed perfect but this doesn’t make it a great option.
James
James8mo ago
still probably cheaper than most of the competitors if you go over the free quota
1luv
1luvOP8mo ago
Where’s the pricing as it doesn’t detail this on the pages website?
Hello, I’m Allie!
Cloudflare Docs
Pricing · Cloudflare Pages docs
Requests to your Functions are billed as Cloudflare Workers requests. Workers plans and pricing can be found in the Workers documentation.
James
James8mo ago
Same as the workers pricing
thanhle
thanhle8mo ago
Yes it is way more cheaper than other service. And DX is great
1luv
1luvOP8mo ago
Thanks I’ll calculate some estimates I have another question maybe someone can help. Is it possible to have two deployments under same TLD so domain.com but one deployment is all static and one is SSR and two routes which dictate when to serve the static deployment and SSG routes without using subdomains ?
Want results from more Discord servers?
Add your server