Skip to content

Commit 201c217

Browse files
committed
A few quick size optimizations
1 parent eb83845 commit 201c217

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

src/index.mjs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,25 +72,23 @@ function isIgnored(node, filter) {
7272
* @param {Function} options.timeoutFn - Custom timeout function
7373
*/
7474
export default function (options) {
75-
options = Object.assign({
76-
timeout: 2e3,
77-
priority: false,
78-
timeoutFn: requestIdleCallback,
79-
el: document,
80-
}, options);
75+
if (!options) options = {};
8176

82-
observer.priority = options.priority;
77+
observer.priority = options.priority || false;
8378

8479
const allowed = options.origins || [location.hostname];
8580
const ignores = options.ignores || [];
8681

87-
options.timeoutFn(() => {
82+
const timeout = options.timeout || 2e3;
83+
const timeoutFn = options.timeoutFn || requestIdleCallback;
84+
85+
timeoutFn(() => {
8886
// If URLs are given, prefetch them.
8987
if (options.urls) {
9088
options.urls.forEach(prefetcher);
9189
} else {
9290
// If not, find all links and use IntersectionObserver.
93-
Array.from(options.el.querySelectorAll('a'), link => {
91+
Array.from((options.el || document).querySelectorAll('a'), link => {
9492
observer.observe(link);
9593
// If the anchor matches a permitted origin
9694
// ~> A `[]` or `true` means everything is allowed
@@ -100,5 +98,5 @@ export default function (options) {
10098
}
10199
});
102100
}
103-
}, {timeout: options.timeout});
101+
}, {timeout});
104102
}

src/prefetch.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const preFetched = {};
2626
*/
2727
function support(feature) {
2828
const link = document.createElement('link');
29-
return (link.relList || {}).supports && link.relList.supports(feature);
29+
return link.relList && link.relList.supports && link.relList.supports(feature);
3030
}
3131

3232
/**

0 commit comments

Comments
 (0)