SSG(nuxt or next) update contents, How is it different from CSR?

50 views Asked by At

In the official documentation, it is written that SSG needs to rebuild the build if the content is updated.

However, you can update the screen by calling API in hooks such as create and mount.

If so, what does it mean to have to rebuild the build to update the content?

Can I think of it as returning a pre-built document to SSG at first and acting like SPA through Hydration?

1

There are 1 answers

0
kissu On

mounted is called only on client-side as you can see here: https://nuxtjs.org/docs/concepts/nuxt-lifecycle/#nuxt-lifecycle
Not sure for created, but you should rather use asyncData or fetch hooks in Nuxt, to get the full benefit of having a meta-framework for SSR/SSG.

What the SSG part means is related to the content generated on the server-side mainly. Go to any page, disable the JS and reload the page.
You'll see the content on the page statically. Modify an API this page is using, then go back to your Nuxt app and reload the page (with JS disabled still), you'll notice that the content is not updated as it should be.

If you do the calls on the client-side, those will always happen and fetch the fresh data all the time. But the point of Nuxt is to ease your life by having both server and client-side content handled for you.

The idea of SSG is mainly to build the whole server-side content at build time. That way, you can host it for free and you don't need to manage a whole Node.js server with the load, security stuff, updates required system-wise etc...