Skip to content

Commit 5f95309

Browse files
committed
golf: save navigator.connection to var;
- reuses unused param name for addl 3 bytes 😇 - 710 gz / 579 br
1 parent 1c94262 commit 5f95309

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

src/prefetch.mjs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,14 @@ const supportedPrefetchStrategy = typeof document !== 'undefined' && support('pr
9595
* @param {Boolean} isPriority - if is "high" priority
9696
* @return {Object} a Promise
9797
*/
98-
function prefetcher(url, isPriority) {
98+
function prefetcher(url, isPriority, conn) {
9999
if (preFetched[url]) {
100100
return;
101101
}
102102

103-
if ('connection' in navigator) {
104-
// Don't prefetch if the user is on 2G...
105-
if ((navigator.connection.effectiveType || '').includes('2g')) {
106-
return;
107-
}
108-
// Don't prefetch if Save-Data is enabled...
109-
if (navigator.connection.saveData) {
110-
return;
111-
}
103+
if (conn = navigator.connection) {
104+
// Don't prefetch if the user is on 2G. or if Save-Data is enabled..
105+
if ((conn.effectiveType || '').includes('2g') || conn.saveData) return;
112106
}
113107

114108
// Wanna do something on catch()?

0 commit comments

Comments
 (0)