Skip to content

Commit

Permalink
core(index.mjs): add support for timeoutFn
Browse files Browse the repository at this point in the history
  • Loading branch information
addyosmani committed Dec 2, 2018
1 parent 783a1b5 commit 524b72e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,18 @@ const prefetchURLs = function (urls, priority) {
* @param {Array} options.urls - Array of URLs to prefetch (override)
* @param {Object} options.el - DOM element to prefetch in-viewport links of
* @param {string} options.priority - Attempt to fetch with higher priority (low or high)
* @param {Number} options.timeout - Timeout after which prefetching will occur
* @param {function} options.timeoutFn - Custom timeout function
* @return {Object} Promise
*/
export default function (options) {
return new Promise((resolve, reject) => {
options = options || {priority: 'low', timeout: 2000};
requestIdleCallback(() => {
options = options || {
priority: 'low',
timeout: 2000,
timeoutFn: requestIdleCallback,
};
options.timeoutFn(() => {
// Prefetch an array of URLs if supplied (as an override)
if (options.urls !== undefined && options.urls.length > 0) {
prefetchURLs(options.urls, options.priority);
Expand Down

0 comments on commit 524b72e

Please sign in to comment.