Skip to content

运行时

¥Runtimes

Next.js 有两个可以在应用中使用的服务器运行时:

¥Next.js has two server runtimes you can use in your application:

  • Node.js 运行时(默认),可以访问生态系统中的所有 Node.js API 和兼容包。

    ¥The Node.js Runtime (default), which has access to all Node.js APIs and compatible packages from the ecosystem.

  • Edge Runtime 包含更有限的 API 集

    ¥The Edge Runtime which contains a more limited set of APIs.

Edge Runtime 是 中间件 的默认运行时。但是,这可以更改为 Node.js 运行时。有关详细信息,请参阅 中间件文档

¥The Edge Runtime is the default runtime for Middleware. However, this can be changed to the Node.js runtime. See the Middleware documentation for more details.

用例

¥Use Cases

  • Node.js Runtime 用于渲染你的应用。

    ¥The Node.js Runtime is used for rendering your application.

  • Edge Runtime 用于中间件(路由规则,如重定向、重写和设置标头)。

    ¥The Edge Runtime is used for Middleware (routing rules like redirects, rewrites, and setting headers).

注意事项

¥Caveats

  • Edge Runtime 不支持所有 Node.js API。某些包可能无法按预期工作。了解有关 Edge 运行时 中不支持的 API 的更多信息。

    ¥The Edge Runtime does not support all Node.js APIs. Some packages may not work as expected. Learn more about the unsupported APIs in the Edge Runtime.

  • Edge Runtime 不支持增量静态再生 (ISR)。

    ¥The Edge Runtime does not support Incremental Static Regeneration (ISR).

  • 两个运行时都可以支持 streaming,具体取决于你的部署基础架构。

    ¥Both runtimes can support streaming depending on your deployment infrastructure.

Next.js v15.2 中文网 - 粤ICP备13048890号