Skip to content

Commit 9fe6036

Browse files
committed
clean(src/index.mjs, src/prefetch.mjs): further reshuffling
1 parent 4aecc0f commit 9fe6036

2 files changed

Lines changed: 18 additions & 18 deletions

File tree

src/index.mjs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
**/
1616

17-
import prefetchURLs from './prefetch.mjs';
17+
import prefetch from './prefetch.mjs';
1818
import 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
*/
5870
export 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
});

src/prefetch.mjs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,4 @@ const prefetch = function (url, priority) {
117117
});
118118
};
119119

120-
/**
121-
* Prefetch an array of URLs using rel=prefetch
122-
* if supported. Falls back to XHR otherwise.
123-
* @param {Array} urls - Array of URLs to prefetch
124-
* @param {string} priority - "priority" of the request
125-
*/
126-
const prefetchURLs = function (urls, priority) {
127-
urls.forEach(url => {
128-
prefetch(url, priority);
129-
});
130-
};
131-
132-
export default prefetchURLs;
120+
export default prefetch;

0 commit comments

Comments
 (0)