Search posts, tags, users, and pages
How can we scale it? Suppose i have millions of static pages. By default nextjs keeps these pages in the local disk. When the number of pages increases then disk size might get exceed.
Hi Rahul, great question! Next.js does minify files etc at build time so that helps a bit with keeping file size down. As far as scaling from a disk perspective you might consider using a cloud server so that your environment can grow with application. Not an expert by any means but I feel like incremental static generation would really work well with page heavy sites - this way you are rebuilding just the pages you need rather the entire site when your data changes. Hope that answered your question 🙏
Hunter Trammell incremental static generation(ISG) - also keeps the page in disk once they are build at run time.
Is there any way to upload the files over CDN like S3 or cloudfare to serve the pages from nearest locations?
Hi Rahul Kumar if you are only using static pages you can use the export process after build to generate a completely static version of your site that would not rely on Node to serve content. You could then upload these files to a cdn to be served. If that doesn't help or still needs some work, id love to look into this further and maybe we can figure out a solution together? Feel free to message me on Twitter!
Hey Rahul Kumar, If you have a web app with millions of pages, you can generate a static page them on demand with the help of getStaticProps and getStaticPaths. And if your website updates frequently you can use ISR too, which rebuilds every page after a fixed interval.
Feel free to ask if you have any more queries :)
Hunter Trammell This way, when we use ISR/ISG(next.js) then for any new page which has been added on run time won't be deployed on CDN. For that we need to rebuild the app and export them.
Building the entire app each time a new page being added is not scalable.
Lalit That is where my question comes. getStaticProps, getStaticPaths and ISR keeps the pages in local disk. Suppose i want to serve the page from CDN to reduce the load on the server. Then can we do this at run time, i mean upload new pages on to the CDN at run time.
Rahul Kumar If you use any service like Vercel, they handle all the caching for you. And moreover once a page is cached, any request to that page will not be counted for any bandwidth of 100GB(free plan on Vercel)!!
If you want to show new content without any rebuilds, you can do it too! But if your content resides beside your source code, you will have to redeploy. But if you have your data hosted in any CMS or a database, you can just add the fallback in getStaticProps to either blocking or true.
If you set it, first it will look for the content in cache, if not found, a static page is built and then cached. In Vercel, pages which are built at runtime are also persisted across deploys.
I hope this clears it, please do ask doubts if any :)
Lalit thanks for your answer.