google chrome - javascript check if image is in browser cache -
i have following code check if external image cached or not
<script type="text/javascript"> function cached(url){ var test = document.createelement("img"); test.src = url; return test.complete || test.width+test.height > 0; } var base_url = "http://www.google.com/images/srpr/nav_logo80.png" alert("expected: true or false\n" + cached(base_url) + "\n\nexpected: false (cache-busting enabled)\n" + cached(base_url + "?" + new date().gettime())); </script>
i following result false false, true false on firefox , ie (which assume first fires false false,then after grabs image, fires true,false, in chrome false, false always
any reason why?
the answer on this question seems work on chrome.
function cached(url){ var test = document.createelement("img"); test.src = url; return test.complete || test.width+test.height > 0; } var base_url = "http://www.google.com/images/srpr/nav_logo80.png" alert("expected: true or false\n" + cached(base_url) + "\n\nexpected: false (cache-busting enabled)\n" + cached(base_url + "?" + new date().gettime()));
answer copy/pasted question, not work.
Comments
Post a Comment