Skip to content

Instantly share code, notes, and snippets.

@theodesp
Last active August 29, 2015 14:01
Show Gist options
  • Save theodesp/12d4804264ef0a8cdb16 to your computer and use it in GitHub Desktop.
Save theodesp/12d4804264ef0a8cdb16 to your computer and use it in GitHub Desktop.
A simple Javascript image preloader
/* Image Preloader
* imgpreload.js
*
* A simple Javascript image preloader
* Created by Theo Despoudis
* (c) 2014 Theo Despoudis. MIT open-source license.
*/
; // Debloat
(function () {
var urls = [
//Put some image urls here and let the Javascript handle the rest
],
images = [];
var L = urls.length;
for (var i = 0; i < L; i += 1) {
var image = new Image();
image.src = urls[i];
images.push(image);
}
})();
@theodesp
Copy link
Author

My first Gist

Usage: Place the images you want to pre-load inside the specified array as strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment