@barba/prefetch
Barba prefetches automatically and cache your pages.
It is mainly inspired by quicklink.
How it works?
Based on Intersection Observer, it processes all eligible links that enter the viewport. Depending on your browser, you may need a polyfill to properly use this plugin.
You can use this feature regardless of the prefetchIgnore
core property. Since the links will be prefetched depending on the viewport, it will prevent the core prefetch process from prefetching a link on enter.
1 | import barba from '@barba/core'; |
On slow network or with a high page weight, the server can take time to prefetch the response and can lead Barba to abort the transition and display a Timeout error message.
See the
timeout
setting to properly manage this behavior.
Options
root
The HTMLElement
or HTMLDocument
to wrap, by default it uses the document.body
.
You can pass a custom element to prevent the plugin from prefetching all links from the entire wrapper. You can also apply a custom limit to only prefetch the 4th first link of the root
element.
timeout
Delay before internal requestIdleCallback
call is canceled, in milliseconds
.
See https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback#parameters.
limit
Number limit of links to be prefetched.
Zero mean “no limit”: the plugin will prefetch all eligible links of the root element.
Here is an example with all options passed to the plugin:
1 | import barba from '@barba/core'; |