Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

第二部分:服务器端渲染

Part 2: Server Side Rendering

正如你在上一章中所读到的,使用客户端渲染(Client-Side Rendered)的 Web 应用程序存在一些局限性。本书的第二部分将讨论如何使用服务器端渲染(Server-Side Rendering)来克服这些限制,并让你的 Leptos 应用获得最佳性能和 SEO。

As you read in the last chapter, there are some limitations to using client-side rendered web applications. This second part of the book will discuss how to use server-side rendering to overcome these limitations and get the best performance and SEO out of your Leptos apps.

:::admonish info

在服务器端使用 Leptos 时,你可以自由选择官方支持的 Actix 或 Axum 集成,或者是社区支持的选择之一。官方选择提供 Leptos 的全套功能,社区选择支持的功能可能较少。详情请查看它们的文档。

我们有多种社区支持的选择,包括与 WinterCG 兼容的运行时(如 Deno 或 Cloudflare)以及服务器端 WASM 运行时(如 Spin)。Viz 和 Pavex 的社区支持集成为传统的服务器选择提供了更多可能性。不建议初学者自己编写集成,但中/高级 Rust 用户可能希望这样做。如果你对此有疑问,欢迎在我们的 Discord 或 Github 上联系我们。

我建议初学者选择 Axum 或 Actix。两者都功能完备,选择哪一个取决于个人偏好。没有错误的选择,但如果你在寻求建议,Leptos 团队目前为新项目默认选择 Axum。

:::

:::admonish info

When working with Leptos on the server side, you’re free to choose either an officially supported Actix or Axum integrations, or one of our community supported choices. The full feature set of Leptos is available with the official choices, the community ones may support less. Check their documentation for details.

We have a variety of community supported choices, including WinterCG-compatible runtimes like Deno or Cloudflare and server-side WASM runtimes like Spin. Community-supported integrations for Viz and Pavex offer more traditional server choices. Writing an integration yourself isn't recommended as a beginner, but medium/advanced Rust users may wish to. Feel free to reach out if you have questions about that on our Discord or Github.

I'd recommend either Axum or Actix for beginners. Both are fully functional and choosing between them is a matter of personal preference. There is no wrong choice there, but if you’re looking for a recommendation, the Leptos team currently defaults to Axum for new projects. :::