Cole
Cole

Reputation: 464

Does making a newly created blog post automatically use SSG?

I'm using generateStaticParams to make all of my blog posts utilize SSG. When I update a blog I revalidate the path. When I create a new one I am also revalidating that path. Do I even need to do this? Will it automatically use SSG? Will it not use SSG until I rebuild and generateStaticParams runs again? I can't find anywhere in the docs that talks about this.

Upvotes: 0

Views: 28

Answers (1)

Raja Jahanzaib
Raja Jahanzaib

Reputation: 640

When you create a new blog post you don't have need to rebuild whole project just do on-demand revalidation. Here's how it works:

  • When you add a new blog post, revalidate the new path.
  • When first user hits with the new blog post route, next.js checks if its included in SSG at build time or in revalidate paths.
  • Then it finds it in revalidate path and firstly render it as SSR ( slightly slower than SSG) and also immediately after rendering, cache it on next.js server.
  • Then when future users hit this new blog post route it serves it from cache. This provides the faster SSG experience.

Now after the first request and caching it will be served as SSG. So, it becomes SSG eventually, but not immediately.

Worth noting: In some more complex scenarios where you might be doing pre-processing in generateStaticParams, a rebuild might be necessary.

Upvotes: -1

Related Questions