Skip to main content

运行时

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 运行时用于渲染你的应用。

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

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

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

注意事项

¥Caveats

  • Edge 运行时不支持所有 Node.js API。有些软件包将无法工作。了解有关 Edge 运行时 中不支持的 API 的更多信息。

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

  • Edge 运行时不支持增量静态再生 (ISR)。

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

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

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