// snippets/Loading/Find-render-blocking-resources.js | sha256:956e114c83da4ff2 | https://github.com/nucliweb/webperf-snippets/blob/main/snippets/Loading/Find-render-blocking-resources.js (()=>{function e(e){return e.name.endsWith("#webperf-snippets")}const r=performance.getEntriesByType("resource").filter(r=>!e(r))[0];if(r&&!("renderBlockingStatus"in r))return{script:"Find-render-blocking-resources",status:"unsupported",error:"renderBlockingStatus API requires Chrome 107+"};const n=performance.getEntriesByType("resource").filter(r=>!e(r)).filter(e=>"blocking"===e.renderBlockingStatus).map(e=>{const r=new URL(e.name);return{name:e.name,shortName:r.pathname.split("/").pop()||r.pathname,type:e.initiatorType,startTime:e.startTime,duration:e.duration,responseEnd:e.responseEnd,size:e.transferSize||0}}).sort((e,r)=>r.responseEnd-e.responseEnd),t=n.length?Math.max(...n.map(e=>e.responseEnd)):0,s=n.reduce((e,r)=>e+r.size,0),o=n.reduce((e,r)=>(e[r.type]=(e[r.type]||0)+1,e),{});if(0===n.length);else{s>0&&(s/1024).toFixed(1);const e=(e,r)=>{const n=Math.round(e/r*100/5);return"█".repeat(n)+"░".repeat(20-n)};n.forEach(r=>{e(r.responseEnd,t),r.size>0&&(r.size/1024).toFixed(1)}),n.map(e=>({Type:e.type,"Response End":e.responseEnd.toFixed(0)+"ms",Duration:e.duration.toFixed(0)+"ms",Size:e.size>0?(e.size/1024).toFixed(1)+" KB":"N/A",Resource:e.name.length>60?"..."+e.name.slice(-57):e.name}))}return{script:"Find-render-blocking-resources",status:"ok",count:n.length,details:{totalBlockingUntilMs:Math.round(t),totalSizeBytes:s,byType:o},items:n.map(e=>({type:e.type,url:e.name,shortName:e.shortName,responseEndMs:Math.round(e.responseEnd),durationMs:Math.round(e.duration),sizeBytes:e.size})),issues:n.length>0?[{code:"render-blocking",severity:"error",message:`${n.length} render-blocking resource(s) delay rendering until ${Math.round(t)}ms`}]:[]}})();