Skip to content
Advertisement

Does Next.js SSG support dyamic data?

I am making a webapp using Next.js and have a question regarding the Static generated sites. My webapp is a blog, and requires a path for each blog entry in the database. If I were to statically generate my webapp and host it on Vercel, would the getStaticPaths function update the paths when a new entry is added?

Advertisement

Answer

That depends on how are you adding new entries. If your are adding it as new file on your project and each time you add a new entry you deploy your whole site too, then yes, each time you re-deploy your site your paths will be updated.

If you’re using some CMS or another way to add new entries that doesn’t re-deploy your site to each time you add new content, what you can do is set the fallback option to true or "blocking" depending on what you prefer. Fallback Docs. This will search for all the routes that were not generated at build time before trigger a 404 (All the new entries).

Now, you probably want to use it along with revalidate on the getStaticProps of your post page. This because if you go to a route before you create that post, it will trigger a 404 and this 404 it wont be updated or regenerated until you re-build your site. You can use revalidate to fix this by setting an amount of time you want to re-generate that page without having to re-build or re-deploy the whole site.

On the Incremental Static Regeneration Docs they use an example pretty similar to yours, you might want to check it out.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement