File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -58,16 +58,6 @@ function extractInViewportLinks(el) {
5858export default function ( options ) {
5959 options = options || { priority : 'low' } ;
6060 requestIdleCallback ( ( ) => {
61- if ( 'connection' in navigator ) {
62- // Don't prefetch if the user is on 2G..
63- if ( navigator . connection . effectiveType && / \s l o w - 2 g | 2 g / . test ( navigator . connection . effectiveType ) ) {
64- return ;
65- }
66- // Don't prefetch if Save-Data is enabled..
67- if ( navigator . connection . saveData ) {
68- return ;
69- }
70- }
7161 // Prefetch an array of URLs if supplied (as an override)
7262 if ( options . urls !== undefined && options . urls . length > 0 ) {
7363 prefetchLinks ( options . urls , options . priority ) ;
Original file line number Diff line number Diff line change @@ -83,13 +83,29 @@ const preFetched = {};
8383
8484const prefetch = function ( url , priority ) {
8585 return new Promise ( resolve => {
86+ if ( 'connection' in navigator ) {
87+ // Don't prefetch if the user is on 2G..
88+ if ( navigator . connection . effectiveType && / \s l o w - 2 g | 2 g / . test ( navigator . connection . effectiveType ) ) {
89+ resolve ( ) ;
90+ return ;
91+ }
92+ // Don't prefetch if Save-Data is enabled..
93+ if ( navigator . connection . saveData ) {
94+ resolve ( ) ;
95+ return ;
96+ }
97+ }
8698 if ( preFetched [ url ] ) {
8799 resolve ( ) ;
88100 return ;
89101 }
90-
91102 if ( priority && priority === `high` ) {
92- highPriFetchStrategy ( url ) ;
103+ highPriFetchStrategy ( url )
104+ . then ( ( ) => {
105+ resolve ( ) ;
106+ preFetched [ url ] = true ;
107+ } )
108+ . catch ( ( ) => { } ) ;
93109 } else {
94110 supportedPrefetchStrategy ( url )
95111 . then ( ( ) => {
You can’t perform that action at this time.
0 commit comments