Skip to content

Commit

Permalink
feat: add option to restrict same origin;
Browse files Browse the repository at this point in the history
- 788 bytes (+17b)
  • Loading branch information
lukeed committed Dec 14, 2018
1 parent 1074d46 commit 2a31aee
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function prefetcher(url) {
* @param {Array} options.urls - Array of URLs to prefetch (override)
* @param {Object} options.el - DOM element to prefetch in-viewport links of
* @param {Boolean} options.priority - Attempt higher priority fetch (low or high)
* @param {Boolean} options.sameOrigin - Restrict prefetching to assets with same origin.
* @param {Array} options.origins - Allowed origins to prefetch (empty allows all)
* @param {Number} options.timeout - Timeout after which prefetching will occur
* @param {function} options.timeoutFn - Custom timeout function
Expand All @@ -62,7 +63,7 @@ export default function (options) {

observer.priority = options.priority;

const allowed = options.origins || [];
const allowed = options.sameOrigin ? [location.hostname] : options.origins || [];

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

0 comments on commit 2a31aee

Please sign in to comment.