Description
Current state
Nuxt's Static Site Generator (nuxt generate
) is growing! I love the static mode when it comes to portfolio pages (or generally, pages that don't include a lot of dynamic data).
Problem
Usually, you use statically generated pages together with a Headless CMS or another external API.
Currently, you can generate the HTML (with static + universal mode) but asyncData
calls are still made during client-side navigation, which means that an external API will likely be called on such a static page.
While it's worth here and there to make these calls even after static generation, it's absolutely not needed (from my POV) for the majority of the pages. Instead, the author/developer could simply issue another build (eg. through Netlify) to update the content.
Also you might encounter different content as asyncData
is not called on the entry route of you static app. (Going from /b to /a can lead to different content than directly accessing /a)
Proposal
As announced by @atinux on Vue Toronto (see his talk at 26:18), I want to propose the full static generation option for nuxt generate
.
Instead of relying on the API calls, we should inline the response of the asyncData
method(s) inside a .json
file (per page) when the generate.fullStatic
flag is enabled in the nuxt.config.js
(the flag name is debatable). Then we can use the .json
file as data source without issues.
Related issues
3rd party modules that apply this approach
https://github.com/DreaMinder/nuxt-payload-extractor
https://github.com/stursby/nuxt-static/