When to Use Static Generation v.s. Server-side Rendering
We recommend using Static Generation (with and without data) whenever possible because your page can be built once and served by CDN, which makes it much faster than having a server render the page on every request.
You can use Static Generation for many types of pages, including:
• Marketing pages
• Blog posts
• E-commerce product listings
• Help and documentation
You should ask yourself: "Can I pre-render this page ahead of a user's request?" If the answer is yes, then you should choose Static Generation.
On the other hand, Static Generation is not a good idea if you cannot pre-render a page ahead of a user's request. Maybe your page shows frequently updated data, and the page content changes on every request.
In that case, you can use Server-side Rendering. It will be slower, but the pre-rendered page will always be up-to-date. Or you can skip pre-rendering and use client-side JavaScript to populate frequently updated data.
When would you use Server-side rendering?
A: When the data needs to be up-to-date with every request
Next.js • 直观的、 基于页面 的路由系统(并支持 动态路由) • 预渲染。支持在页面级的 静态生成 (SSG) 和 服务器端渲染 (SSR) • 自动代码拆分,提升页面加载速度 • 具有经过优化的预取功能的 客户端路由 • 内置 CSS 和 Sass 的支持,并支持任何 CSS-in-JS 库 • 开发环境支持 快速刷新 • 利用 Serverless Functions 及 API 路由 构建 API 功能 • 完全可扩展
When to Use Static Generation v.s. Server-side Rendering We recommend using Static Generation (with and without data) whenever possible because your page can be built once and served by CDN, which makes it much faster than having a server render the page on every request. You can use Static Generation for many types of pages, including: • Marketing pages • Blog posts • E-commerce product listings • Help and documentation You should ask yourself: "Can I pre-render this page ahead of a user's request?" If the answer is yes, then you should choose Static Generation. On the other hand, Static Generation is not a good idea if you cannot pre-render a page ahead of a user's request. Maybe your page shows frequently updated data, and the page content changes on every request. In that case, you can use Server-side Rendering. It will be slower, but the pre-rendered page will always be up-to-date. Or you can skip pre-rendering and use client-side JavaScript to populate frequently updated data. When would you use Server-side rendering? A: When the data needs to be up-to-date with every request