All Projects → feross → preload-img

feross / preload-img

Licence: MIT license
Preload an image on a webpage

Programming Languages

javascript
184084 projects - #8 most used programming language

preload-img travis npm downloads javascript style guide

Preload an image on a webpage

Works best with browserify!

install

npm install preload-img

usage

If you know you'll need to load an image later, you can preload it upfront (when your web app loads) to make sure that it loads instantly later.

var preload = require('preload-img')

preload('/img/spinner.gif')
preload('/img/another-image.png')

Works best when the image has far-future HTTP cache headers set.

real-world example

You can see this module in action on Magic Keyboard. Check the Network Tab in the Web Inspector to see that an image for each letter of the alphabet is loaded before the user has actually typed any letters.

license

MIT. Copyright (c) Feross Aboukhadijeh.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].