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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dobuki/asset-loader

v1.0.40

Published

Package for loading assets.

Downloads

97

Readme

asset-loader

npm version Version License

icon

Description

The asset loader is a package used for preloading assets for your app or game. The idea is this:

  • We first list all assets that we plan to load and keep in memory. The loading process is going to start, limited at 3 parallel downloads. You don't need to wait for all assets to download, you can already start the app.
  • Whenever your app needs an asset from a URL, pass it as await loader.getUrl(url) instead of url. This will wait ensure that the asset for that URL is downloaded, and it will replace the URL with the BLOB url. The blob URL is the equivalent URL saved in memory, so you won't be hitting the server again.
  • The download process could take a while, and there are assets you don't need immediately. But as soon as an asset is needed, its download gets reprioritized to the top. There is also a priority parameter you can pass to ensure your download gets higher priority:
    • LOW: New requests do not get re-prioritized.
    • MEDIUM: New requests get prioritized, but not above the 3 simultaneous download limits.
    • HIGH (default if no priority specified): New request initiate immediately and the limit can go up to 4 simultaneous downloads.
    • TOP: New request initiate immediately and the download limit is disregarded.

Usage

Preloading

Instantiate the loader, then preload all assets you will eventually need.

const loader = new Loader();
loader.load(url1);
loader.load(url2);
loader.load(url3);
//...

Note that loader.load return a promise, but we don't put await because we're not waiting for those to finish.

Fetch asset on demand

Then your app will need some assets immediately:

const assetToShow = await loader.getUrl(url);
const img = new Image();
img.src = assetToShow;

The URL you're passing to img.src will be a blob URL, which is shown immediately if the asset is in memory, or will wait for the await otherwise. Since you'll be progressively downloading all assets, they will eventually all be available immediately.

Configure

You can change the configuration when instantiating the loader:

const loader = new Loader({
  waitBetweenLoader: 1000,  //  default 10
  retries: 5,               //  default 3
  maxParallelLoad: 5,       //  default 3
});
  • waitBeetweenLoader: Millisecs to wait before initiating a new download after the first 3.
  • retries: If the download fails, try again 3 times.
  • maxParallelLoad: At most 3 simultaneous downloads, but you can change that.

Demo

Below is a demo on @dobuki/asset-loader being used to load all assets within a Github repo.

Click here to view example.