generate vs prerender

I have a site which is mainly static, but has a couple of server/api endpoints. From what I understand / have experienced in development, I can't use nuxi generate as I need a live Nitro instance to manage API requests. As the site is static, but I need Nitro, should I use route rules to prerender everything?
routeRules: {
'**': { prerender: true },
},
routeRules: {
'**': { prerender: true },
},
I just want to get clear on a) the best pipeline to get the best performance and b) to have a better understanding of what Nuxt does to give users a site (as it's not like PHP where you can see the phsical files from the outset). From what I can see in the .output folder: - nuxi generate / serve creates / serves .html files and payloads from public/path/to/file - nuxi build / preview creates / serves equivalent mjs files under server/chunks etc So I assume that "prerendering" in the build case is not physical html files but mjs files which Nitro / Vue can more efficiently present as HTML? Thanks
10 Replies
Attacler/Bart
Attacler/Bart5mo ago
from what i understand: generate -> make static html/css/js so your site works without any serverside rendering build -> build your nuxt application for production so you can run it in SSR
davestewart
davestewart5mo ago
I guess I'm wondering if I can do generate and get API endpoints, or if not, what are the most performant settings to choose for an SSR site
Attacler/Bart
Attacler/Bart5mo ago
no, generate only makes clientsided code, not serversided code
Attacler/Bart
Attacler/Bart5mo ago
on how to make performant SSR, there are a bunch of articles, for example this article talks about it: https://www.vuemastery.com/blog/nuxt-3-performance-pt-1/
Vue Mastery
Nuxt 3 Performance Pt 1 | Vue Mastery
In this article, we’ll be looking at Performance in Nuxt 3 applications and how we can boost the performance of our apps.
davestewart
davestewart5mo ago
Thanks for the link, but the topics it covers are more for client side performance, hydration, etc. My Lighthouse performance is already 94; I just want more info on the mechanics of SSR, routeRules, etc. and how it all works together which I think is a bit light in the docs. Looks like there's also { static: true } in Nitro; what is this? How it is it different from prerender? Or should I use { isr: true } ? And for example @manniL / TheAlexLichter demos nitro.prerender.routes; I wonder why this vs Nuxt's own routeRules (which I presume are passed to Nitro anyway). TL;DR I just want more info how all these libs are configured and layered together
davestewart
davestewart5mo ago
This article is getting there (it also calls out the docs for lacking info): https://blog.risingstack.com/nuxt-3-rendering-modes/
RisingStack Engineering
Comparing Nuxt 3 Rendering Modes: SWR, ISR, SSR, SSG, SPA - RisingS...
Learn from our experience in streamlining Nuxt 3 for SEO and speed, navigating scarce documentation and exploring rendering modes.
manniL
manniL5mo ago
planning a video on this for a while
davestewart
davestewart5mo ago
I've been digging through the output files, clicking into the import maps, reformatting stuff, extracting compiled JSON; it's really interesting to see how it all fits together. Interestingly my (currently one) API route had a whole load of unused imports (commented for testing / clarity here). Just in case they're needed? How come the imports from the original file would not have sufficed?
No description
davestewart
davestewart5mo ago
FWIW I managed to break my Nuxt Content production site by settinging route rules to { isr: true }. Pages load on first navigate, but subsequent navigations to Content pages render your entire content database as the markdown / element node strtucture they're stored in. I don't know enough about ISR to know if this is a bug or expected behaviour, but suspect bug. Don't do this at home, kids!
manniL
manniL5mo ago
definitely a bug 😄
Want results from more Discord servers?
Add your server
More Posts
How to start a project (Nuxt 3, Composition API, MongoDB.)First of all sorry about this question, sounds extremly basic, but I spent the whole day trying diffEmpty response in pinia store from server API using $fetchOn a server route `server/api/offices/index.post.ts`, supabase is (successfully) used to update an "Layout transition with javascript hook not workingI wanted to animate between layouts using **anime.js**. But it seems that the layout transition javaRender child elements when parent's v-show is false?I'm pretty sure I've read about a way to make this work before, but I can't find it anymore. BasicaHow to keep order of global middlewares with Nuxt Layers?It seems that Nuxt Layers won't follow alphabetical order of global middlewares. The layer that exte🐛 Nuxt muddling elements in rendered output #bugI've seen this before but thought it was maybe a Nuxt Content bug (I even [raised an issue](https://How do you add a directory of files to publicAssets at build time?I'm trying to add a directory of files (wasm and tflite models) to my publicAssets directory at builUsing Nuxt3 behind Apache proxy?Hi, has anyone experience on getting Nuxt to work behind an Apache proxy? I've tried anything I ca$fetch catches error, but not able to read bodyHi, I must be missing something. I'm attempting to get a $fetch error and it's JSON body, but it siBaseURL + Uncommon Configuration With Reverse ProxyWe have a Nuxt3 app which we have created which is intended to be deployed to various locations as a