nuxt-hub / core

Build full-stack applications with Nuxt on CloudFlare, with zero configuration.
https://hub.nuxt.com
Apache License 2.0
992 stars 57 forks source link

Nuxt consumes the same amount of CPU even after prerendering (Nuxthub enabled) #124

Closed rahulkumarsingh73690 closed 5 months ago

rahulkumarsingh73690 commented 5 months ago

Even after enabling routeRules prerender in some routes nuxt, some routes still consume the same amount of CPU.

rahulkumarsingh73690 commented 5 months ago

Is there any way to enable caching to prevent more CPU usage?

atinux commented 5 months ago

Do you have the deployed website or some infos to share to help debug?

If the page is pre-rendered, it should be served from the CDN directly so not calling the Nuxt server (worker).

rahulkumarsingh73690 commented 5 months ago

I don't have stats but pre-rendered still counts as a worker request and CPU usage. I have a traffic site where I am facing this issue.

I will try get data from small project

And one more thing

'/blog/**': { prerender: true },

Does nothing only

'/blog/': { prerender: true },

Works

rahulkumarsingh73690 commented 5 months ago

Please check full discussion on discord with @manniL - https://discord.com/channels/473401852243869706/1244656036002926645

atinux commented 5 months ago

So, Nitro cannot follow the link as we did not configure the crawlLinks option but we should not in the hybrid mode

One solution is to use the prerenderRoutes()[https://nuxt.com/docs/api/utils/prerender-routes) util in your blog.vue page to list all the other blog post pages.

Example:

<script setup>
const { data: posts } = await useFetch('/api/posts')

prerenderRoutes(posts.value.map(post => `/blog/${post.slug}`))
</script>
rahulkumarsingh73690 commented 5 months ago

https://github.com/unjs/nitro/pull/2498