Skip to content

Commit

Permalink
docs: add info about Link prefetch option (QwikDev#6814)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darrefull authored Aug 21, 2024
1 parent 072c38f commit cd1e68c
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions packages/docs/src/routes/docs/(qwikcity)/api/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,38 @@ export default component$(() => {
);
});
```

### Prefetch

Whether Qwik should prefetch and cache the target page of this `Link`, this includes invoking any `routeLoader$`, `onGet`, etc.

This **improves UX performance** for client-side (**SPA**) navigations.

Prefetching occurs when a the Link enters the viewport in production (`on:qvisibile`), or with `mouseover`/`focus` during dev.

Prefetching will not occur if the user has the **data saver** setting enabled.

Setting this value to `"js"` will prefetch only javascript bundles required to render this page on the client, `false` will disable prefetching altogether.

> Warning: if you have a menu with many links, all of them will be loaded immediately when you enter the production page, which may result with too many requests
```tsx
import { component$ } from '@builder.io/qwik';
import { Link } from '@builder.io/qwik-city';

export default component$(() => {
return (
<div>
<Link href="/a" prefetch={false}>
page will not be prefetched
</Link>
<Link href="/b" prefetch="js">
page js will be prefetched
</Link>
<Link href="/c">
page content & js will be prefetched
</Link>
</div>
);
});
```

0 comments on commit cd1e68c

Please sign in to comment.