Skip to content

Commit

Permalink
Collect number of assets served from browser cache
Browse files Browse the repository at this point in the history
  • Loading branch information
soulgalore committed Oct 12, 2023
1 parent 99c1c3b commit 97fca1e
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions browserscripts/pageinfo/resources.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
(function() {
(function () {
const resources = window.performance.getEntriesByType('resource');

let resourceDuration = 0;
let servedFromCache = 0;
let servedFromCacheSupported = false;
for (let i = 0; i < resources.length; i++) {
resourceDuration += resources[i].duration;
if (resources[i].deliveryType !== undefined) {
servedFromCacheSupported = true;
if (resources[i].deliveryType === 'cache') {
servedFromCache++;
}
}
}

return {
const info = {
count: Number(resources.length),
duration: Number(resourceDuration)
duration: Number(resourceDuration),
};

if (servedFromCacheSupported === true) {
info.servedFromCache = Number(servedFromCache);
}
})();

return info;
})();

0 comments on commit 97fca1e

Please sign in to comment.