在页面加载触发预取后附加 link 和 rel = prefetch 或 prerender 吗?

Does appending a link with rel = prefetch or prerender after page load trigger prefetch?

我打算使用 JS 在页面加载后将这样的预取 link 注入到文档中:

<link rel="prefetch" href="https://www.example.com">

这会启动预取吗?或者 link 与 rel= prefetchpreload 只有在页面加载时它们是文档的一部分时才会受到尊重?

是的,它应该也有效。

The specs 表示

The resource hint link's may be specified in the document markup, MAY be provided via the HTTP Link header, and MAY be dynamically added to and removed from the document.

最后一部分是我们感兴趣的部分。

它甚至 one of the use-cases 被这份文件公开:

The prefetch can be used to implement a "reactive prefetch strategy" that leverages the knowledge of where the user is heading next and enables the application to begin prefetching critical resources in parallel with the navigation request.

To achieve the above behavior the application can listen for click, or other user and application generated events, and dynamically insert relevant prefetch relations for critical resources required by the next navigation. In turn, the user agent can fetch the hinted resources in parallel with the navigation request, making the critical resources available sooner.