Skip to content

Commit 47dbaf5

Browse files
committed
Add handling for effectiveconnectiontype
1 parent ce0aa40 commit 47dbaf5

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

index.mjs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ function extractInViewportLinks(el) {
4242
export default function quicklink(options) {
4343
options = options || {};
4444
requestIdleCallback(() => {
45+
if ('connection' in navigator) {
46+
// Don't prefetch if the user is on 2G..
47+
if (navigator.connection.effectiveType && /\slow-2g|2g/.test(navigator.connection.effectiveType)) {
48+
return;
49+
}
50+
}
4551
// Prefetch an array of URLs if supplied (as an override)
4652
if (options.urls !== undefined && options.urls.length > 0) {
4753
fetchLinks(options.urls);
@@ -50,7 +56,9 @@ export default function quicklink(options) {
5056
let el = options.el || document;
5157
extractInViewportLinks(el).then((urls) => {
5258
fetchLinks(urls);
53-
});
54-
}
59+
});
60+
}
5561
});
5662
}
63+
64+
// TODO: add preload / high prio?

0 commit comments

Comments
 (0)