Created
July 18, 2014 21:28
-
-
Save megantaylor/d5ce714c27cd9c40c770 to your computer and use it in GitHub Desktop.
Preloading images is useful: Instead of loading an image when the user request it, we preload them in the background so they are ready to be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
var cache = []; | |
// Arguments are image paths relative to the current page. | |
$.preLoadImages = function() { | |
var args_len = arguments.length; | |
for (var i = args_len; i--;) { | |
var cacheImage = document.createElement('img'); | |
cacheImage.src = arguments[i]; | |
cache.push(cacheImage); | |
} | |
} | |
jQuery.preLoadImages("image1.gif", "/path/to/image2.png"); | |
//http://engineeredweb.com/blog/09/12/preloading-images-jquery-and-javascript |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment