diff --git a/src/chunks.mjs b/src/chunks.mjs index 5d617e43..fe849007 100644 --- a/src/chunks.mjs +++ b/src/chunks.mjs @@ -121,7 +121,12 @@ export function listen(options) { export function prefetch(url, isPriority, conn) { if (conn = navigator.connection) { // Don't prefetch if using 2G or if Save-Data is enabled. - if (conn.saveData || /2g/.test(conn.effectiveType)) return; + if (conn.saveData) { + return Promise.reject(new Error('Cannot prefetch, Save-Data is enabled')); + } + if (/2g/.test(conn.effectiveType)) { + return Promise.reject(new Error('Cannot prefetch, network conditions are poor')); + } } // Dev must supply own catch() @@ -138,4 +143,4 @@ export function prefetch(url, isPriority, conn) { } }) ); -} \ No newline at end of file +} diff --git a/src/index.mjs b/src/index.mjs index ccdb78af..3b2c6ee5 100644 --- a/src/index.mjs +++ b/src/index.mjs @@ -114,7 +114,12 @@ export function listen(options) { export function prefetch(url, isPriority, conn) { if (conn = navigator.connection) { // Don't prefetch if using 2G or if Save-Data is enabled. - if (conn.saveData || /2g/.test(conn.effectiveType)) return; + if (conn.saveData) { + return Promise.reject(new Error('Cannot prefetch, Save-Data is enabled')); + } + if (/2g/.test(conn.effectiveType)) { + return Promise.reject(new Error('Cannot prefetch, network conditions are poor')); + } } // Dev must supply own catch()