Skip to content

Commit

Permalink
docs: prefetch tap fallback on slow connection and ignore slow connec…
Browse files Browse the repository at this point in the history
…tion option (#5393)

Co-authored-by: Bjorn Lu <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
  • Loading branch information
3 people authored Nov 22, 2023
1 parent 5d25b87 commit e55df27
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/content/docs/en/guides/prefetch.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ You can specify a strategy for an individual link by passing it to the `data-ast

Each strategy is fine-tuned to only prefetch when needed and save your users' bandwidth. For example:

- If a visitor is using [data saver mode](https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation/saveData) or has a [slow connection](https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation/effectiveType), prefetching will be turned off.
- If a visitor is using [data saver mode](https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation/saveData) or has a [slow connection](https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation/effectiveType), prefetch will fallback to the `tap` strategy.
- Quickly hovering or scrolling over links will not prefetch them.
- Links that use the `viewport` strategy are prefetched with a lower priority to avoid clogging up the network.

Expand Down Expand Up @@ -114,7 +114,14 @@ prefetch('/about', { with: 'fetch' });
prefetch('/about', { with: 'link' });
```

The `prefetch()` API includes the same [data saver mode](https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation/saveData) and [slow connection](https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation/effectiveType) detection, so that it only prefetches when needed.
The `prefetch()` API includes the same [data saver mode](https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation/saveData) and [slow connection](https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation/effectiveType) detection so that it only prefetches when needed.

To ignore slow connection detection, you can use the `ignoreSlowConnection` option:

```js
// Prefetch even on data saver mode or slow connection
prefetch('/about', { ignoreSlowConnection: true });
```

Make sure to only import `prefetch()` in client-side scripts as it relies on browser APIs.

Expand Down

0 comments on commit e55df27

Please sign in to comment.