async-preloader
    Preparing search index...

    Class AsyncPreloader

    AsyncPreloader: assets preloader using ES2017 async/await and fetch.

    It exports an instance of itself as default so you can:

    import Preloader from "async-preloader";

    await Preloader.loadItems([]);

    to use directly as a singleton or

    import { AsyncPreloader as Preloader } from "async-preloader";

    const preloader = new Preloader();
    await preloader.loadItems([]);

    if you need more than one instance.

    Index

    Constructors

    Properties

    defaultBodyMethod: BodyMethod = "blob"

    Default body method to be called on the Response from fetch if no body option is specified on the LoadItem

    defaultLoader: LoaderKey = LoaderKey.Text

    Default loader to use if no loader key is specified in the LoadItem or if the extension doesn't match any of the AsyncPreloader.loaders extensions

    items: Map<string, LoadedValue> = ...

    Object that contains the loaded items

    Methods

    • Load an item and parse the Response as arrayBuffer

      Parameters

      Returns Promise<ArrayBuffer>

      Fulfilled value of parsed Response

    • Load an item in one of the following cases:

      • item's "loader" option set as "Audio"
      • item's "src" option extensions matching the loaders Map
      • direct call of the method

      Parameters

      Returns Promise<LoadedValue>

      Fulfilled value of parsed Response according to the "body" option. Defaults to an HTMLAudioElement with a blob as srcObject or src.

    • Load an item and parse the Response as blob

      Parameters

      Returns Promise<Blob>

      Fulfilled value of parsed Response

    • Load an item and parse the Response as bytes

      Parameters

      Returns Promise<Uint8Array<ArrayBufferLike>>

      Fulfilled value of parsed Response

    • Load a font via FontFace or check a font is loaded via FontFaceObserver instance

      Parameters

      • item: LoadItem

        Item to load (id correspond to the font family name).

      Returns Promise<string | FontFace>

      Fulfilled value with FontFace instance or initial id if no src provided.

    • Load an item and parse the Response as formData

      Parameters

      Returns Promise<FormData>

      Fulfilled value of parsed Response

    • Load an item in one of the following cases:

      • item's "loader" option set as "Image"
      • item's "src" option extensions matching the loaders Map
      • direct call of the method

      Parameters

      Returns Promise<LoadedValue>

      Fulfilled value with a decoded HTMLImageElement instance of or a parsed Response according to the "body" option. Defaults to a decoded HTMLImageElement.

    • Load the specified manifest (array of items)

      Parameters

      • items: string[] | LoadItem[]

        Items to load

      Returns Promise<LoadedValue[]>

      Resolve when all items are loaded, reject for any error

    • Load an item and parse the Response as json

      Parameters

      Returns Promise<JSON>

      Fulfilled value of parsed Response

    • Load a manifest of items

      Parameters

      • src: string

        Manifest src url

      • key: string = "items"

        Manifest key in the JSON object containing the array of LoadItem.

      Returns Promise<LoadedValue[]>

    • Load an item and parse the Response as text

      Parameters

      Returns Promise<string>

      Fulfilled value of parsed Response

    • Load an item in one of the following cases:

      • item's "loader" option set as "Video"
      • item's "src" option extensions matching the loaders Map
      • direct call of the method

      Parameters

      Returns Promise<LoadedValue>

      Fulfilled value of parsed Response according to the "body" option. Defaults to an HTMLVideoElement with a blob as srcObject or src.

    • Load an item in one of the following cases:

      • item's "loader" option set as "Xml"
      • item's "src" option extensions matching the loaders Map
      • direct call of the method

      Parameters

      • item: LoadItem

        Item to load (need a mimeType specified or default to "application/xml")

      Returns Promise<LoadedXMLValue>

      Result of Response parsed as a document.