Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
images = [
'http://cdn.discogs.com/yqU-8wqol13SCGfPg2sYy9gBjb4=/100x100/filters:strip_icc():format(jpeg):mode_rgb()/discogs-images/R-3996200-1351777283-1914.jpeg.jpg',
'http://cdn.discogs.com/U2oncEZe50hAlYSoFbVOkIf1Y0s=/fit-in/300x300/filters:strip_icc():format(jpeg):mode_rgb()/discogs-images/R-3578188-1440480186-6359.jpeg.jpg'
]
_preload = (src)->
new Promise (resolve, reject)->
image = document.createElement 'img'
image.src = src
image.onload = -> resolve image
image.style.display = 'none'
document.body.appendChild image
setTimeout reject, 30000
render = (images)->
# show something using all images
preload = (images)->
Promise.all (_preload src for src in images)
preload(images).then render
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment