Skip to content

Instantly share code, notes, and snippets.

@stenvdb
Created June 6, 2012 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stenvdb/2880975 to your computer and use it in GitHub Desktop.
Save stenvdb/2880975 to your computer and use it in GitHub Desktop.
JQuery: Check if image is in browser cache
alert("Expected: true or false\n" +
cached(big_img)
+ "\n\nExpected: false (cache-busting enabled)\n" +
cached(big_img + "?" + new Date().getTime()));
function cached(url){
var test = document.createElement("img");
test.src = url;
return test.complete || test.width+test.height > 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment