工作原理(续)
sequenceDiagram
participant U1 as 用户1
participant U2 as 用户2
participant U3 as 用户N
participant FS as 文件系统缓存
participant React as React 渲染引擎
U1->>FS: 访问 /blog
FS-->>U1: 返回 blog.html(不渲染)
U2->>FS: 访问 /blog
FS-->>U2: 返回 blog.html(不渲染)
U3->>FS: 访问 /blog
FS-->>U3: 返回 blog.html(不渲染)
Note over React: React 渲染引擎完全空闲<br/>CPU 开销为零
动态页面(不会被缓存)
使用了动态函数的页面会被标记为动态,每次请求都重新渲染:
// app/profile/page.tsx
import { cookies } from "next/headers";
export default async function ProfilePage() {
// 使用了动态函数 → 页面变成动态的
const token = (await cookies()).get("token")?.value;
const res = await fetch("https://api.example.com/user/me", {
headers: { Authorization: `Bearer ${token}` },
});
const user = await res.json();
return <div>{user.name}</div>;
}