Skip to content

Instantly share code, notes, and snippets.

@carlos-sanchez
Created November 15, 2013 00:19
Show Gist options
  • Save carlos-sanchez/7476906 to your computer and use it in GitHub Desktop.
Save carlos-sanchez/7476906 to your computer and use it in GitHub Desktop.
Facebook like image preloader. Ever noticed how fast images load when paging through a Facebook photo album? This is because Facebook is preloading each of these images into your browser’s cache before you even view them. Here’s how you can achieve a similar behavior on your website using some jQuery magic.
var nextimage = "/images/some-image.jpg";
$(document).ready(function(){
window.setTimeout(function(){
var img = $("<img>").attr("src", nextimage).load(function(){
//all done
});
}, 100);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment