Skip to main content

预渲染成静态 HTML 文件

如果你使用静态托管服务提供商托管 build,则可以使用 react-snapshotreact-snap 为应用中的每个路由或相关链接生成 HTML 页面。当 JavaScript 包加载后,这些页面将无缝地变得活跃或“水合”。

¥If you’re hosting your build with a static hosting provider you can use react-snapshot or react-snap to generate HTML pages for each route, or relative link, in your application. These pages will then seamlessly become active, or “hydrated”, when the JavaScript bundle has loaded.

也有机会在静态托管之外使用它,以在生成和缓存路由时减轻服务器的压力。

¥There are also opportunities to use this outside of static hosting, to take the pressure off the server when generating and caching routes.

预渲染的主要好处是,无论你的 JavaScript 包是否成功下载,你都可以通过 HTML 有效负载获取每个页面的核心内容。它还增加了应用的每个路由被搜索引擎选中的可能性。

¥The primary benefit of pre-rendering is that you get the core content of each page with the HTML payload—regardless of whether or not your JavaScript bundle successfully downloads. It also increases the likelihood that each route of your application will be picked up by search engines.

你可以阅读有关 零配置预渲染(也称为快照)在这里 的更多信息。

¥You can read more about zero-configuration pre-rendering (also called snapshotting) here.