export class CachedResourceObserver { private loaded = { networkOrDisk : 0 , memory : 0 , } ; private observer ? : PerformanceObserver ; constructor ( ) { if ( ! window . PerformanceObserver ) return ; const cb = ( entries ) => { const e = entries . getEntries ( ) ; e . forEach ( ( entry ) => { if ( entry . initiatorType === 'script' || entry . initiatorType === 'link' ) { if ( entry . name . indexOf ( window . location . host ) > - 1 && entry . transferSize === 0 ) { this . loaded . memory ++ ; } else { this . loaded . networkOrDisk ++ ; } } } ) ; } ; this . observer = new PerformanceObserver ( cb ) ; this . observer . observe ( { type : 'resource' , buffered : true , } ) ; } public getCounts ( ) { return this . loaded ; } public destroy ( ) { this . observer ?. disconnect ( ) ; } }