image-preload
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

image-preload

Simple, framework-agnostic image preloader. Async, sync, background, foreground, whatever!

Installation

npm install --save image-preload

Or you can use a browser script available from https://unpkg.com/image-preload@1.0.6/browser/main.js.

Minimal usage
import Preload from "image-preload";
 
Preload(["https://i.imgur.com/VCr4saa.png"]);

Async, in background usage

import Preload from "image-preload";
 
Preload(["https://i.imgur.com/VCr4saa.png"], {
  inBackground: true,
  toBase64: true,
  onSingleImageComplete: base64 => console.log(base64)
});

Sorting options usage

import Preload, { Order } from "image-preload";
 
Preload(["https://i.imgur.com/VCr4saa.png"], { order: Order.AllAtOnce });
// or
Preload(["https://i.imgur.com/VCr4saa.png"], { order: Order.InOrder });

All options

type Options = {
  order?: Order;
  timeout?: number;
  shouldContinueOnFail?: boolean;
  toBase64?: boolean;
  inBackground?: boolean;
  onSingleImageFail?: Function;
  onSingleImageComplete?: Function;
  onComplete?: Function;
};

Defaul options

const defaultOptions = {
  order: Order.InOrder,
  timeout: 0,
  shouldContinueOnFail: true,
  toBase64: false,
  inBackground: false,
  onSingleImageFail: () => {},
  onSingleImageComplete: () => {},
  onComplete: () => {}
};

Package Sidebar

Install

npm i image-preload

Weekly Downloads

43

Version

1.0.6

License

MIT

Unpacked Size

18.4 kB

Total Files

10

Last publish

Collaborators

  • minieggs40