npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@motionharvest/asset-preloader

v1.0.4

Published

A lightweight asset preloader for JavaScript applications.

Readme

Asset Preloader

Asset Preloader is a lightweight JavaScript module for efficiently preloading assets in web applications. It supports images, videos, sounds, 3D models, and other file types with features such as event-driven progress tracking, retry mechanisms, batch loading, and customizable UI options.

Features

  • Singleton Pattern – Ensures a single instance is used for asset management.
  • Event-Driven Architecture – Fires progress, complete, error, and assetLoaded events.
  • Customizable UI – Disable the default UI and use a custom progress display.
  • Retry Mechanism – Retries failed assets up to a defined limit before fallback.
  • Batch Loading – Controls how many assets load simultaneously.
  • Default Asset Fallbacks – Replace missing assets with predefined placeholders.
  • Asset-Specific Callbacks – Respond when an individual asset is loaded.

Installation

Using NPM

npm install @motionharvest/asset-preloader

Usage

Importing the Preloader

import AssetPreloader from '@motionharvest/asset-preloader';

Initializing the Preloader

const preloader = new AssetPreloader(true, true); // Debug mode, Custom UI enabled

Setting Default Assets

preloader.setDefaults({
    png: 'assets/default.png',
    glb: 'assets/default.glb',
    mp3: 'assets/default.mp3'
});

Loading Assets

const assetsToLoad = [
    'assets/image.png',
    'assets/video.mp4',
    'assets/missing_model.glb',
    'assets/sound.mp3'
];
preloader.loadAssets(assetsToLoad, 3, 15000); // Batch size 3, timeout 15s

Listening to Events

preloader.addEventListener('progress', (event) => {
    console.log(`Progress: ${event.detail.progress.toFixed(2)}% for ${event.detail.url}`);
});

preloader.addEventListener('assetLoaded', (event) => {
    console.log(`Asset loaded: ${event.detail.url}`);
});

preloader.addEventListener('error', (event) => {
    console.warn(`Asset failed to load: ${event.detail}, using fallback if available.`);
});

preloader.addEventListener('complete', () => {
    console.log('All assets loaded successfully!');
});

Retrieving a Loaded Asset

const imageUrl = preloader.getAsset('assets/image.png');
if (imageUrl) {
    const img = document.createElement('img');
    img.src = imageUrl;
    document.body.appendChild(img);
}

API Reference

new AssetPreloader(debug = false, useCustomUI = false)

Creates a singleton instance of the preloader.

  • debug (boolean) – Enables logging output.
  • useCustomUI (boolean) – Disables default loading UI if true.

.setDefaults(defaults)

Sets default fallback assets per file type.

  • defaults (object) – Key-value pairs of file extensions and default asset URLs.

.loadAssets(assetList, batchSize = null, timeoutDuration = 10000)

Loads an array of assets with optional batch size and timeout settings.

  • assetList (array) – List of asset URLs to preload.
  • batchSize (number) – How many assets to load simultaneously.
  • timeoutDuration (number) – Maximum time in milliseconds before an asset is considered failed.

.getAsset(url)

Retrieves the loaded asset's blob URL.

  • url (string) – The original asset URL.
  • Returns: A blob URL if the asset is loaded, otherwise null.

Events

  • progress – Fired on loading progress updates.

    preloader.addEventListener('progress', (event) => {
        console.log(`Progress: ${event.detail.progress.toFixed(2)}% for ${event.detail.url}`);
    });
  • assetLoaded – Fired when an individual asset finishes loading.

    preloader.addEventListener('assetLoaded', (event) => {
        console.log(`Asset loaded: ${event.detail.url}`);
    });
  • error – Fired when an asset fails to load.

    preloader.addEventListener('error', (event) => {
        console.warn(`Failed to load: ${event.detail}`);
    });
  • complete – Fired when all assets have been loaded.

    preloader.addEventListener('complete', () => {
        console.log('All assets loaded successfully!');
    });

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request.

Author

Developed by Aaron Sherrill.


Enjoy using Asset Preloader! 🚀