NuxtJs generate for dynamic websites?

In universal mode, nuxt generate is for static site generation. nuxt build is for SSR site.

In 2.13.0, Nuxt introduced a target: static feature, make sure to check it.

A static site has the best performance, and it is easy to deploy on nginx or other services, like Netlify.

By default, nuxt generate only render your static home page and /users page, not the dynamic /user/:id route.

But you can config nuxt to help you generate the dynamic routes.

  1. If you have a fixed set of users, you can use functions to generate the routes.

  2. If the users data is constantly in change, you can config nuxt to fallback to SPA on the dynamic routes. But you can't get any benefit for SEO on the dynamic routes.

For SPA fallback, in the generate config, define a custom page for SPA fallback:

export default {
  generate: {
    fallback: "custom_sap_fallbackpage.html"
  }
}

Config the fallback page for unknow route in your deployment, for example, in Nginx:

location / {
    try_files $uri /custom_sap_fallbackpage.html;
}

nuxt build will build you a SSR site. The html is rendered on the server and sent to the client. It add some work load on the server and maybe is not that easy to deploy, but the main gain is the SEO. And to some users with low end devices or slow internet connection, maybe your site will perform better than depolying in SPA mode.

Basically, you need to consider:

  1. The website's content is static or constantly changing?

nuxt generate for static. nuxt generate or nuxt build or spa mode for sites with dynamic routes.

  1. Do you need SEO?

SPA wouldn't get any SEO.

  1. How you deploy the site?

For static hosting service, only nuxt generate or spa mode will work.

  1. your website is heavy with js code, and you want best performance for user with slow internet and slow devices. Or SEO is important for your site with a lot of dynamic content.

SSR is for you, use nuxt build.