Skip to content

Commit 9205c20

Browse files
committed
docs(README): add API, polyfills, expand recipes
1 parent 18bea81 commit 9205c20

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,42 @@ The above options are best for multi-page sites. Single-page apps have a few opt
4646
* Call `quicklink()` against a specific DOM element / component
4747
* Call `quicklink({urls:[...]})` with a custom set of URLs to prefetch
4848

49+
## API
50+
51+
`quicklink` accepts an optional options object with the following parameters:
52+
53+
* `el`: DOM element to observe for in-viewport links to prefetch
54+
* `urls`: Static array of URLs to prefetch (instead of observing `document` or a DOM element links in the viewport)
55+
* `timeout`: Integer for the `requestIdleCallback` timeout. A time in milliseconds by which the browser must execute prefetching. Defaults to 2 seconds.
56+
* `priority`: String specifying preferred priority for fetches. Defaults to `low`. `high` will attempt to use the `fetch()` API where supported (rather than rel=prefetch)
57+
58+
TODO:
59+
* Explore detecting file-extension of resources and using [rel=preload](https://w3c.github.io/preload/) for `high` priority fetches
60+
* Explore using [Priority Hints](https://github.com/WICG/priority-hints) for importance hinting
61+
62+
## Polyfills
63+
64+
`quicklink`:
65+
66+
* Includes a very small fallback for [requestIdleCallback](https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback)
67+
* Requires `IntersectionObserver` to be supported (see [CanIUse](https://caniuse.com/#feat=intersectionobserver)). We recommend conditionally polyfillng this feature with a service like Polyfill.io:
68+
69+
```html
70+
<script src="https://polyfill.io/v2/polyfill.min.js?features=IntersectionObserver"></script>
71+
```
72+
4973
## Recipes
5074

75+
**Set a custom timeout for prefetching resources**
76+
77+
Defaults to 2 seconds (via `requestIdleCallback`). Here we override it to 4 seconds:
78+
79+
```js
80+
quicklink({
81+
timeout: 4000
82+
});
83+
```
84+
5185
**Set the DOM element to obseve for in-viewport links**
5286

5387
Defaults to `document` otherwise.

0 commit comments

Comments
 (0)