跳到主要内容

运行时

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.

用例

¥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.