Skip to content

Instantly share code, notes, and snippets.

@pjvandehaar
Last active August 29, 2015 13:57
Show Gist options
  • Save pjvandehaar/9621247 to your computer and use it in GitHub Desktop.
Save pjvandehaar/9621247 to your computer and use it in GitHub Desktop.
<html>
<head>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js'></script>
<script>
function isCached(img_src) {
var dfd = $.Deferred();
var start_time = $.now();
var img;
var timeout = setTimeout(function() {
img.off('load');
img.attr('src', '');
dfd.resolve(undefined);
}, 100); //TODO: test failure threshold on slow computers
img = $('<img style="display:none">')
.load(function() {
clearTimeout(timeout);
dfd.resolve($.now() - start_time);
})
.attr('src', img_src);
return dfd.promise();
}
var imgs = {
calvin: "https://portal.calvin.edu/CookieAuth.dll?GetPic?formdir=3&image=portal_logo.png",
msu: "https://mail.msu.edu/msu_web/_images/wordmark-msu.gif",
hope: "http://www.hope.edu/sites/all/themes/hope/logo.png",
mtu: "http://www.mtu.edu/mtu_resources/images/home/home-sprite.png"
};
Object.keys(imgs).forEach(function(school) {
isCached(imgs[school]).done(function(time) {
$(function() {
$('body').append('<pre>' + [time, school, imgs[school]] + '</pre>');
});
});
});
</script>
</head>
<body>
<a href='detect_school.html'>Reload without flushing cache</a>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment