You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+17-2Lines changed: 17 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,9 +10,18 @@ Quicklink makes subsequent navigations to pages load faster. It:
10
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
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
12
13
+
## Installation
14
+
15
+
For use with [node](http://nodejs.org) and [npm](https://npmjs.com):
16
+
17
+
```sh
18
+
npm install --save quicklink
19
+
```
13
20
14
21
## Usage
15
22
23
+
Once initialized, `quicklink` will automatically prefetch URLs for links that are in-viewport during idle time.
24
+
16
25
Quickstart:
17
26
18
27
```html
@@ -31,14 +40,20 @@ import quicklink from "dist/quicklink.mjs";
31
40
quicklink();
32
41
```
33
42
43
+
The above options are best for multi-page sites. Single-page apps have a few options available for using quicklink with a router:
44
+
45
+
* Call `quicklink()` once a navigation to a new route has completed
46
+
* Call `quicklink()` against a specific DOM element / component
47
+
* Call `quicklink{urls:[...]}` with a custom set of URLs to prefetch
48
+
34
49
## Recipes
35
50
36
51
**Set the DOM element to obseve for in-viewport links**
37
52
38
53
Defaults to `document` otherwise.
39
54
40
55
```js
41
-
let elem =document.getElementById('stuff');
56
+
let elem =document.getElementById('carousel');
42
57
quicklink({
43
58
el: elem
44
59
});
@@ -57,7 +72,7 @@ quicklink({
57
72
**Set the request priority for prefetches**
58
73
59
74
Defaults to low-priority (`rel=prefetch` or XHR). For high-priority,
0 commit comments