Skip to content

Commit

Permalink
for images that have to go to origin, border them red
Browse files Browse the repository at this point in the history
  • Loading branch information
cvazac committed Sep 29, 2017
1 parent 6b03d7d commit e1cc9e5
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions perfbar.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,34 +905,35 @@ var UW = unsafeWindow;
// Shows Cache Status overlay
//
if (getState("cacheStatus")) {
window.addEventListener("load", function() {
Array.prototype.forEach.call(document.getElementsByTagName('img'), function(img){
var entry = performance.getEntriesByName(img.src)[0]
if (!entry) return

if (cachedInBrowser(entry)) {
img.style.border = 'solid 3px green'
img.style.opacity = '0.5'
} else if (cachedAtEdge(entry)) {
img.style.border = 'solid 3px blue'
img.style.opacity = '0.5'
} else console.info(entry)
})
window.addEventListener("load", function () {
Array.prototype.forEach.call(document.getElementsByTagName('img'), function (img) {
var entry = performance.getEntriesByName(img.src)[0]
if (!entry) return

img.style.opacity = '0.5'
if (cachedInBrowser(entry)) {
img.style.border = 'solid 3px green'
} else if (cachedAtEdge(entry)) {
img.style.border = 'solid 3px blue'
} else {
img.style.border = 'solid 3px red'
}
})

function cachedInBrowser({requestStart, responseStart, transferSize}) {
return transferSize === 0 || (responseStart - requestStart < 20)
}
function cachedAtEdge({name, serverTiming}) {
var origin
(serverTiming || []).forEach(function(st) {
if (st.name === 'origin' || st.metric === 'origin') {
console.info(name, st.description)
origin = st.description === false
}
})
return origin === false
function cachedInBrowser({requestStart, responseStart, transferSize}) {
return transferSize === 0 || (responseStart - requestStart < 20)
}

function cachedAtEdge({name, serverTiming}) {
var origin
(serverTiming || []).forEach(function (st) {
if (st.name === 'origin' || st.metric === 'origin') {
origin = st.description === 'true'
}
})
})
return origin === false
}
})
}

//
Expand Down

0 comments on commit e1cc9e5

Please sign in to comment.