Skip to content

Commit

Permalink
Merge branch 'master' of github.com:nicjansma/perfbar.js
Browse files Browse the repository at this point in the history
  • Loading branch information
nicjansma committed Oct 2, 2017
2 parents 9a433e4 + e1cc9e5 commit 70eed00
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 @@ -909,34 +909,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 70eed00

Please sign in to comment.