N
Nuxt4d ago
valerio

What is the difference between static and prerender in routerules?

What is the difference between static and prerender in routerules?
2 Replies
kapa.ai
kapa.ai4d ago
Hi @valerio. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To answer your question about the difference between static and prerender in route rules for Nuxt, let's examine the key distinctions: 1. static route rule: - The static rule sets an infinite cache duration for a route. - It's equivalent to setting a very long cache time. - Content will be cached until the next deployment. 2. prerender route rule: - The prerender rule generates the route's content at build time. - It creates static HTML files for the specified routes during the build process. - These pre-rendered pages are then served as static assets. The main differences are: - Timing: static affects caching at runtime, while prerender generates content at build time. - Content generation: prerender actually creates the content in advance, whereas static just caches whatever is generated on the first request. - Flexibility: static content can still be dynamically generated on first request, while prerender content is fixed at build time. Here's an example of how you might use these in your nuxt.config.ts:
export default defineNuxtConfig({
routeRules: {
'/static-page': { static: true },
'/pre-rendered-page': { prerender: true }
}
})
export default defineNuxtConfig({
routeRules: {
'/static-page': { static: true },
'/pre-rendered-page': { prerender: true }
}
})
In this example, /static-page will be cached indefinitely after its first generation, while /pre-rendered-page will be generated during the build process. It's worth noting that both options are part of Nuxt's hybrid rendering capabilities, allowing you to optimize different routes in your application for performance and SEO. Source: Nuxt Docs - Hybrid Rendering Remember that the prerender option is particularly useful for content that doesn't change often and can be generated at build time, while static is more suitable for content that might change but can be cached for long periods. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4d ago
<@612831566565212160> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?