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
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
Thanks @HardlyWorkin' but you deploy as a static-deployment ?
No, you would deploy the entire thing as an SSR deployment, with some components that don't actually require SSR
Don't you then loose all the static site benefits? It's then just a normal full-stack deployment
Which benefits?
Static pages are all pre-generated there are no requests for anything, they are cached so can be served by CDN as static files.
I should note that even with SSR, the pages are still served from the CDN
The only downside is that requests are billed
but each time they are requested the server is generating the content.
Yes, but that server is also the CDN
Every CDN server in the Cloudflare Fleet also runs Pages
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.
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
👌
How do you specify which routes are pre-rendered?
Those still invoke Functions tho right?
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
Dont add the export const runtime = edge to that route, then is is static generated at build time.
yes
So under the Pro tier, you get unlimited static requests, but none of these would be seen as "static requests" ?
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
So how’s this deployment billed if some routes are static and some SSR?
Every request(other than requests for assets) are billed
But if it were pure static deployment it wouldn’t be right?
That is correct
That’s a shame, CloudFlare seemed perfect but this doesn’t make it a great option.
still probably cheaper than most of the competitors if you go over the free quota
Where’s the pricing as it doesn’t detail this on the pages website?
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.
Same as the workers pricing
Yes it is way more cheaper than other service. And DX is great
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 ?