Learn How to Pre-render Pages Using Static Generation with Next.js

JJ Kasper
5 分钟阅读

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Praesent elementum facilisis leo vel fringilla est ullamcorper eget. At imperdiet dui accumsan sit amet nulla facilities morbi tempus.

Congue nisi vitae suscipit tellus mauris a diam maecenas sed. Enim ut sem viverra aliquet eget. Volutpat consequat mauris nunc congue nisi vitae. Vel pharetra vel turpis nunc eget lorem dolor sed viverra.

What is Static Generation?

Static Generation is a method of pre-rendering where the HTML pages are generated at build time. This means that the page HTML is generated once (typically on a CI/CD pipeline), not on every request, and then reused for each request.

This approach provides significant performance benefits because the page is already rendered and ready to serve. There's no need for a server to compute data or render templates on every visit.

When to Use Static Generation?

We recommend using Static Generation whenever possible because it's much faster for users to load the page. You should ask yourself: "Can I pre-render this page ahead of a user's request?"

Static Generation is a great choice for pages that:

  • Don't require real-time data
  • Can be cached by a CDN
  • Don't change frequently
  • Are the same for all users