Posted By

fuelishways on 06/19/14


Tagged


Versions (?)

facebook-like image preloader


 / Published in: jQuery
 

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.

  1. var nextimage = "/images/some-image.jpg";
  2. $(document).ready(function(){
  3. window.setTimeout(function(){
  4. var img = $("<img>").attr("src", nextimage).load(function(){
  5. //all done
  6. });
  7. }, 100);
  8. });

Report this snippet  

You need to login to post a comment.