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 🙏

© 2026 – Pkg Stats / Ryan Hefner

bc-asset-loader

v1.0.7

Published

A JavaScript library that asynchronously preloads images, web fonts, and videos in bulk.

Downloads

46

Readme

bc-asset-loader

A JavaScript library that asynchronously preloads images, fonts, and videos in bulk. You can read loading progress via the progress property, which is useful for progress bars or percentage UIs. It is well suited when you do not want to show the page until images and fonts have finished downloading, or when you want to prevent layout shift.


Installation

npm

npm install bc-asset-loader

Script tag or CDN (jsDelivr)

<script src="bc-asset-loader.js"></script>
<script src="https://cdn.jsdelivr.net/gh/beicundun/bc-asset-loader@main/dist/bc-asset-loader.js"></script>

Demo

From the root of this repository, install dependencies with npm install, then run npm run dev to start the development server and open the demo.


Usage

With npm

import BcAssetLoader from 'bc-asset-loader';

const loader = new BcAssetLoader({
  image: [
    { url: '/img/hero.jpg' },
    { url: '/img/bg.png' },
  ],
  font: [
    { url: '/fonts/NotoSansJP-Regular.woff2', family: 'Noto Sans JP', weight: '400' },
    { url: '/fonts/NotoSansJP-Bold.woff2', family: 'Noto Sans JP', weight: '700' },
  ],
  extFont: [
    {
      url: 'https://fonts.googleapis.com/css2?family=Roboto:wght@400;700',
      families: [
        { family: 'Roboto', weights: ['400', '700'] },
      ],
    },
  ],
  video: [
    { url: '/video/intro.mp4' },
  ],
  onComplete: () => {
    console.log('All assets loaded');
  },
});

loader.load();

// Update progress bar
const progressBar = document.querySelector('.progress-bar');

requestAnimationFrame(function update() {
  progressBar.style.width = `${loader.progress * 100}%`;
  if (!loader.loaded) requestAnimationFrame(update);
});

With a script tag or CDN (jsDelivr)

<!-- Local file -->
<script src="bc-asset-loader.js"></script>

<!-- CDN (jsDelivr) -->
<script src="https://cdn.jsdelivr.net/gh/beicundun/bc-asset-loader@main/dist/bc-asset-loader.js"></script>

<script>
  const loader = new BcAssetLoader({
    image: [{ url: '/img/hero.jpg' }],
    onComplete: () => {
      console.log('All assets loaded');
    },
  });
  loader.load();
</script>

API

Constructor

new BcAssetLoader(options: BcAssetLoaderOptions)

BcAssetLoaderOptions

| Property | Type | Required | Description | |----------|------|----------|-------------| | image | Array | Optional | List of images to load | | font | Array | Optional | List of self-hosted fonts to load | | extFont | Array | Optional | List of externally hosted fonts (e.g. Google Fonts) to load | | video | Array | Optional | List of videos to load | | onComplete | Function | Optional | Callback invoked when all assets have finished loading |

interface BcAssetLoaderOptions {
  image?: {
    url: string;
  }[];
  font?: {
    url: string;
    family: string;
    weight?: string;
    style?: string;
    stretch?: string;
  }[];
  extFont?: {
    url: string;
    families: {
      family: string;
      weights?: string[];
      style?: 'normal' | 'italic';
    }[];
  }[];
  video?: {
    url: string;
  }[];
  onComplete?: () => void;
}

Methods

load(): Promise<void>

Starts loading all assets.
The onComplete callback is invoked after loading completes.

await loader.load();

Properties

loaded: boolean

Whether loading has finished for all assets.

loadedAmount: number

How much has been loaded, as the sum of the following:

| Asset type | When / how much is added | |------------|--------------------------| | image | +1 per completed file | | font | +1 per completed file | | extFont | +1 when all fonts for one URL are done | | video | Buffered fraction (01) added in real time |

Only video contributes fractional values, so loadedAmount is not necessarily an integer.

totalAmount: number

Total workload, as the sum of the following:

| Asset type | How it is counted | |------------|-------------------| | image | Number of image files specified | | font | Number of font files specified | | extFont | Number of URLs specified (1 URL = 1) | | video | Number of video files specified |

progress: number

Loading progress (01), computed as loadedAmount / totalAmount.

onComplete: () => void

Reference to the onComplete callback passed to the constructor.


Error handling

  • If an individual asset fails to load, an error is logged to the console, that asset is skipped, and loading continues.
  • When all load attempts have finished, loaded becomes true and onComplete is called.
  • Assets that failed to load are excluded from the progress calculation.

TypeScript

Type definitions (dist/bc-asset-loader.d.ts) are bundled; no extra install is required.


License

MIT