1414 * limitations under the License.
1515**/
1616
17- import prefetchURLs from './prefetch.mjs' ;
17+ import prefetch from './prefetch.mjs' ;
1818import requestIdleCallback from './request-idle-callback.mjs' ;
1919
2020/**
@@ -42,7 +42,19 @@ function extractInViewportLinks(el) {
4242 observer . observe ( link ) ;
4343 } ) ;
4444 } ) ;
45- }
45+ } ;
46+
47+ /**
48+ * Prefetch an array of URLs using rel=prefetch
49+ * if supported. Falls back to XHR otherwise.
50+ * @param {Array } urls - Array of URLs to prefetch
51+ * @param {string } priority - "priority" of the request
52+ */
53+ const prefetchURLs = function ( urls , priority ) {
54+ urls . forEach ( url => {
55+ prefetch ( url , priority ) ;
56+ } ) ;
57+ } ;
4658
4759/**
4860 * Prefetch an array of URLs if the user's effective
@@ -56,16 +68,16 @@ function extractInViewportLinks(el) {
5668 * @param {string } options.priority - Attempt to fetch with higher priority (low or high)
5769 */
5870export default function ( options ) {
59- options = options || { priority : 'low' } ;
71+ options = options || { priority : 'low' } ;
6072 requestIdleCallback ( ( ) => {
6173 // Prefetch an array of URLs if supplied (as an override)
6274 if ( options . urls !== undefined && options . urls . length > 0 ) {
63- prefetchLinks ( options . urls , options . priority ) ;
75+ prefetchURLs ( options . urls , options . priority ) ;
6476 } else {
6577 // Element to extract in-viewport links for
6678 const el = options . el || document ;
6779 extractInViewportLinks ( el ) . then ( urls => {
68- prefetchLinks ( urls , options . priority ) ;
80+ prefetchURLs ( urls , options . priority ) ;
6981 } ) ;
7082 }
7183 } ) ;
0 commit comments