images-cache
v1.4.1
Published
Cache images as base64 for faster browser display
Downloads
62
Readme
images-cache
Cache images as base64 for faster browser display
Features
- load a bunch of urls and notify progress via a promise
- store these urls binary content as base64
- fallback to original url when image not found in cache
:warning: As images are downloaded via AJAX, the remote urls must have CORS enabled
QuickStart
import imagesCache from 'images-cache';
const images = [
'http://path/to/image.jpg',
'http://path/to/image2.jpg'
];
imagesCache.load(images).progress(status => {
console.log('progress', status.loaded, status.total);
}).then(() => {
imagesCache.get('http://path/to/image.jpg'); // -> returns the base64 version, ex: data:image/jpg;base64,...
imagesCache.get('http://path/to/unknown/image.jpg'); // -> returns 'http://path/to/unknown/image.jpg'
}).done();
API
load(urls)
: load a bunch of urls and store internally as base64.get(url)
: return base64 version of an existing url, and return original url if not found in cacheclear()
: empty the current cache
Scripts
- npm run readme :
node ./node_modules/node-readme/bin/node-readme.js
- npm run test :
find ./spec -iname '*.spec.js' -exec ./node_modules/.bin/babel-node {} \; | ./node_modules/.bin/tap-spec
- npm run build :
./node_modules/.bin/browserify ./src/index.js -o ./dist/index.js
- npm run watch :
./node_modules/.bin/watchify ./src/index.js -o ./dist/index.js
Dependencies
Package | Version | Dev --- |:---:|:---: browser-request | 0.3.3 | ✖ q | 1.4.1 | ✖ babel | 5.6.23 | ✔ babel-eslint | 3.1.23 | ✔ babelify | 6.1.2 | ✔ browserify | 11.0.1 | ✔ eslint | 1.0.0-rc-1 | ✔ eslint-config-airbnb | 0.0.6 | ✔ mockery | 1.4.0 | ✔ node-readme | 0.1.8 | ✔ tap-spec | 4.0.2 | ✔ tape | 4.0.0 | ✔ watchify | 3.3.1 | ✔
Author
Julien Bouquillon [email protected] undefined
License
- MIT : http://opensource.org/licenses/MIT