Skip to content

Commit 0a26a65

Browse files
committed
docs(README): add how it works, usage and recipes.
1 parent 9fe6036 commit 0a26a65

1 file changed

Lines changed: 68 additions & 1 deletion

File tree

README.md

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,69 @@
11
# quicklink
2-
Faster web page loads by prefetching in-viewport links in the background
2+
> Faster subsequent page-loads by prefetching in-viewport links in the background
3+
4+
## How it works
5+
6+
Quicklink makes subsequent navigations to pages load faster. It:
7+
8+
* **Detects links within the viewport** (using `IntersectionObsever`)
9+
* **Waits until the browser is idle** (using `requestIdleCallback`)
10+
* **Checks if the user isn't on a slow connection** (using `navigator.connection.effectiveType`) or has data-saver enabled (using `navigator.connection.saveData`)
11+
* **Prefetches URLs to the links** (using `<link rel=prefetch>` or XHR). Provides some control over the request priority (can switch to `fetch()` if supported).
12+
13+
14+
## Usage
15+
16+
Quickstart:
17+
18+
```html
19+
<!-- Include quicklink from dist -->
20+
<script src="dist/quicklink.js"></script>
21+
<!-- Initialize (you can do this to whenever you want) -->
22+
<script>
23+
quicklink();
24+
</script>
25+
```
26+
27+
ES Module import:
28+
29+
```js
30+
import quicklink from "dist/quicklink.mjs";
31+
quicklink();
32+
```
33+
34+
## Recipes
35+
36+
**Set the DOM element to obseve for in-viewport links**
37+
38+
Defaults to `document` otherwise.
39+
40+
```js
41+
let elem = document.getElementById('stuff');
42+
quicklink({
43+
el: elem
44+
});
45+
```
46+
47+
**Set a custom array of URLs to be prefetched**
48+
49+
If you would prefer to provide a static list of URLs to be prefetched, instead of detecting those in-viewport, customizing URLs is supported.
50+
51+
```js
52+
quicklink({
53+
urls: ['2.html','4.html']
54+
});
55+
```
56+
57+
**Set the request priority for prefetches**
58+
59+
Defaults to low-priority (`rel=prefetch` or XHR). For high-priority,
60+
attempts to use fetch() or falls back to XHR.
61+
62+
```js
63+
quicklink({ priority: 'high' });
64+
```
65+
66+
## License
67+
68+
Licensed under the Apache-2.0 license.
69+

0 commit comments

Comments
 (0)