node-tailor
Version:
Tailor assembles a web page from multiple fragments
2 lines • 2.28 kB
JavaScript
(function(n,e){function t(){for(var n,e=c.length-1;e>=0;e--)if((n=c[e]).hasAttribute("data-pipe"))return n.removeAttribute("data-pipe"),n}function o(){0!==l.length||!n.readyState||"complete"!==n.readyState&&"interactive"!==n.readyState||v.onDone()}function r(n){return null!=n&&"object"==typeof n&&"function"==typeof n.then}function i(n,e,t,i){v.onBeforeInit(t,i);var a=n(e),f=function(){l.pop(),v.onAfterInit(t,i),o(t)};r(a)?a.then(f).catch(f):f()}function a(n,t){!1 in e||p.push({name:n,duration:Number(t),entryType:"tailor",startTime:e.now()||Date.now()-e.timing.navigationStart})}function f(n){return function(e){v[n]=e}}var u={},d={},c=n.getElementsByTagName("script"),l=[],p=[],s=function(){},v={onStart:s,onBeforeInit:s,onAfterInit:s,onDone:s};return{placeholder:function(n){u[n]=t()},start:function(n,e,o){d[n]=t(),e&&(l.push(n),v.onStart(o,n),require([e]))},end:function(n,e,r){var a,f=u[n],c=d[n],p=t(),s=c;if(f){do{a=s,s=s.nextSibling,f.parentNode.insertBefore(a,f)}while(a!==p);f.parentNode.removeChild(f)}for(a=c.nextSibling;a&&1!==a.nodeType;)a=a.nextSibling;a===p&&(a=void 0),c.parentNode.removeChild(c),p.parentNode.removeChild(p),e&&require([e],function(e){var t=e&&e.__esModule?e.default:e;if("function"!=typeof t)return l.pop(),v.onBeforeInit(r,n),v.onAfterInit(r,n),void o();i(t,a,r,n)})},loadCSS:/* @preserve - loadCSS: load a CSS file asynchronously. [c]2016 @scottjehl, Filament Group, Inc. Licensed MIT */
function(e){function t(e){if(n.body)return e();setTimeout(function(){t(e)})}function o(){i.addEventListener&&i.removeEventListener("load",o),i.media="all"}var r,i=n.createElement("link"),a=(n.body||n.getElementsByTagName("head")[0]).childNodes;r=a[a.length-1];var f=n.styleSheets;i.rel="stylesheet",i.href=e,i.media="only x",t(function(){r.parentNode.insertBefore(i,r.nextSibling)});var u=function(n){for(var e=i.href,t=f.length;t--;)if(f[t].href===e)return n();setTimeout(function(){u(n)})};return i.addEventListener&&i.addEventListener("load",o),i.onloadcssdefined=u,u(o),i},onStart:f("onStart"),onBeforeInit:f("onBeforeInit"),onAfterInit:f("onAfterInit"),onDone:function(n){var e=v.onDone;v.onDone=function(){e(),n()}},addPerfEntry:a,addTTFMPEntry:function(n){a("ttfmp",n)},getEntries:function(){return p}}})(window.document,window.performance);