-
Notifications
You must be signed in to change notification settings - Fork 2
/
client.ts
39 lines (37 loc) · 841 Bytes
/
client.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/// <reference no-default-lib="true" />
/// <reference lib="dom" />
/**
* Client only code: prefetch, service worker, etc.
*/
import { listen } from "quicklink";
function prefetchLinks() {
setTimeout(() => {
const anchorParents: NodeListOf<HTMLElement> = document.querySelectorAll(
"[data-prefetch]",
);
anchorParents.forEach((el) =>
listen({
limit: 10,
el,
delay: 2000,
ignores: [
(uri) => {
return uri.includes("#") || uri === location.toString();
},
],
})
);
}, 5000);
}
export function init() {
if (
document.readyState === "complete" ||
document.readyState === "interactive"
) {
prefetchLinks();
} else {
document.addEventListener("DOMContentLoaded", prefetchLinks, {
once: true,
});
}
}