I am testing around with Nuxt.js to generate a static website.
Is it possible to generate a 100% static site when using an API to fetch data, so that one can get rid of the API and requests?
Based on my tests so far that all the files are generated properly and being hosted on the Github Pages and can be reached, except:
.html
file is generated with the data already during the generate process.Using asyncData to get the data for the components from the API.
Building SPAs with CrafterCMS and NuxtNuxtJS is a robust framework built on top of Vue to offer a smooth single-page web application development experience.
Nuxt, one of the most popular Vue frameworks for new web apps, can greatly improve your app performance and SEO.
The solution was to use vuex (state management) and populate the state with the data during the generation process.
The state will be already populated in the generated .html
file
For more information please refer to the this thread where it is being discussed.
Example:
async fetch({ store }) {
if (_.isEmpty(store.getters['tags/getTags'])) {
await store.dispatch('tags/fetchTags');
}
},
fetchTags
is the actions making a request to api and populate the statetags
state is not already populated, then populate it by making a request to an apinuxt generate
the state will be populated for the deployment, hence to api request won't be sentIf anyone have a better solution, please share, I will gladly accept that answer as a correct one :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With