A mostly static site
Goal: most pages are HTML files made at build time, and a few are rendered per request or in the browser. In Nuxt this is routeRules with prerender, swr and ssr: false.
- Pick a preset with a server, so the pages that are not prerendered have somewhere to run, and say what is prerendered.
prerender: truein a rule marks a path,prerender.routeslists more, andcrawl: truefollows the links of the pages it renders.swrserves a stored copy for that many seconds and renders again in the background.ssr: falsesends a shell that the browser fills in:
import { defineConfig } from "hamur"
export default defineConfig({
framework: "react",
preset: "node",
prerender: { routes: ["/about", "/pricing"], crawl: true, failOnError: true },
routeRules: {
"/": { prerender: true },
"/blog/**": { swr: 600 },
"/dashboard/**": { ssr: false },
},
})
- Build and look at what was written.
hamur buildwrites the prerendered pages as files and the server answers the rest;failOnError: truefails the build when a page does not prerender:
hamur build --preset node
hamur preview
- If every page can be prerendered, drop the server: with the
staticpresethamur generateprerenders every page without params and the output is files for any static host. A path inprerender.routesis written as a full page even underssr: false; the other pages of that kind share the shell200.html.
A page that reads the request (a cookie, the session) cannot be prerendered: add ensureStatic: true to its rule and the build names the line that reads it. A page that changes without a deploy needs swr or isr, and revalidateTag or revalidatePath drops it when its data changes (Caching and ISR).
See also: Route rules and prerender, Rendering modes, Deploy.