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
luv
luv7mo 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
luv
luv7mo 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?
luv
luv7mo 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
luv
luv7mo 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
luv
luv7mo 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
James7mo 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
luv
luv7mo ago
👌 How do you specify which routes are pre-rendered?
Hello, I’m Allie!
Those still invoke Functions tho right?
James
James7mo 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
thanhle7mo ago
Dont add the export const runtime = edge to that route, then is is static generated at build time.
James
James7mo ago
yes
luv
luv7mo 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
luv
luv7mo 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
luv
luv7mo ago
But if it were pure static deployment it wouldn’t be right?
Hello, I’m Allie!
That is correct
luv
luv7mo ago
That’s a shame, CloudFlare seemed perfect but this doesn’t make it a great option.
James
James7mo ago
still probably cheaper than most of the competitors if you go over the free quota
luv
luv7mo 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
James7mo ago
Same as the workers pricing
thanhle
thanhle7mo ago
Yes it is way more cheaper than other service. And DX is great
luv
luv7mo 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