Skip to content

Commit 2a31aee

Browse files
committed
feat: add option to restrict same origin;
- 788 bytes (+17b)
1 parent 1074d46 commit 2a31aee

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/index.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ function prefetcher(url) {
4848
* @param {Array} options.urls - Array of URLs to prefetch (override)
4949
* @param {Object} options.el - DOM element to prefetch in-viewport links of
5050
* @param {Boolean} options.priority - Attempt higher priority fetch (low or high)
51+
* @param {Boolean} options.sameOrigin - Restrict prefetching to assets with same origin.
5152
* @param {Array} options.origins - Allowed origins to prefetch (empty allows all)
5253
* @param {Number} options.timeout - Timeout after which prefetching will occur
5354
* @param {function} options.timeoutFn - Custom timeout function
@@ -62,7 +63,7 @@ export default function (options) {
6263

6364
observer.priority = options.priority;
6465

65-
const allowed = options.origins || [];
66+
const allowed = options.sameOrigin ? [location.hostname] : options.origins || [];
6667

6768
options.timeoutFn(() => {
6869
// If URLs are given, prefetch them.

0 commit comments

Comments
 (0)