Skip to content

实验性客户端预渲染

类型:boolean
默认:false

¥Type: boolean
Default: false

Added in: astro@4.2.0

在受支持的浏览器中启用在客户端上预渲染预取页面。

¥Enables pre-rendering your prefetched pages on the client in supported browsers.

此功能使用实验性的 Speculation Rules Web API 并全局增强默认 prefetch 行为以在客户端上预渲染链接。你可能希望在启用此功能之前查看 在客户端预渲染时可能存在的风险

¥This feature uses the experimental Speculation Rules Web API and enhances the default prefetch behavior globally to prerender links on the client. You may wish to review the possible risks when prerendering on the client before enabling this feature.

在你的 astro.config.mjs 中启用客户端预渲染以及任何所需的 prefetch 配置选项:

¥Enable client side prerendering in your astro.config.mjs along with any desired prefetch configuration options:

astro.config.mjs
{
prefetch: {
prefetchAll: true,
defaultStrategy: 'viewport',
},
experimental: {
clientPrerender: true,
},
}

继续使用你网站上任何 <a /> 链接上的 data-astro-prefetch 属性来选择加入预取。不是将 <link> 标签附加到文档头部或使用 JavaScript 获取页面,而是将 <script> 标签附加到相应的推测规则。

¥Continue to use the data-astro-prefetch attribute on any <a /> link on your site to opt in to prefetching. Instead of appending a <link> tag to the head of the document or fetching the page with JavaScript, a <script> tag will be appended with the corresponding speculation rules.

客户端预渲染需要浏览器支持。如果不支持推测规则 API,prefetch 将回退到支持的策略。

¥Client side prerendering requires browser support. If the Speculation Rules API is not supported, prefetch will fallback to the supported strategy.

请参阅 预取指南 以了解更多 prefetch 选项和用法。

¥See the Prefetch Guide for more prefetch options and usage.

Astro 中文网 - 粤ICP备13048890号