-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtransparent-fetch.min.js
2 lines (2 loc) · 1.32 KB
/
transparent-fetch.min.js
1
2
/* [email protected] · MIT · Transparent CDN*/
(function(a,b){'object'==typeof exports&&'undefined'!=typeof module?module.exports=b():'function'==typeof define&&define.amd?define(b):a.pre=b()})(this,function(){'use strict';async function a(a='a'){await new Promise(a=>'complete'===document.readyState?a():void document.addEventListener('DOMContentLoaded',a,!1)),c(a).forEach(a=>{a.host!==location.host||(a.addEventListener('mouseover',a=>this.load(a.currentTarget)),a.addEventListener('touchstart',a=>this.load(a.currentTarget)))})}async function b(a=''){let b=d(a.href||a,'transparent-fetch.load():');if(b=b.split('#')[0],this.loaded[b])return this.loaded[b];this.loaded[b]=!0;let c=document.createElement('link');return c.rel='prefetch',c.href=b,document.head.appendChild(c),this.loaded[b]}var c=(a,b=document)=>[...b.querySelectorAll(a)],d=(a,b='')=>{if(!a)throw new Error(`${b} the argument has to be an url or a <a> element`);if('A'===a.nodeName)throw new Error(`${b} argument element is missing the href="" or it is empty`);if(a.nodeName)throw new Error(`${b} expected an anchor <a> element, received "${a.nodeName}"`);if('string'!=typeof a)throw new Error(`${b} expected a string, received ${typeof a}`);return a};var e=new function(){this.loaded={},this.init=a,this.load=b,this.report=a=>console.log('Error:',a),this.init()};return e});