Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

asset-preloader

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asset-preloader

A tiny Typescript asset preloader for the browser via XHR2. It can preload assets of different file types and composite progress together and supports multiple event subscriptions.

  • 0.1.0
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

asset-preloader

A tiny Typescript asset preloader for the browser via XHR2. It can preload assets of different file types and composite progress together and supports multiple event subscriptions.

Get started

Install

yarn add asset-preloader
# or
npm install --save asset-preloader

Use

import { createPreloader } from 'asset-preloader'

const preloader = createPreloader()

preloader
  .fetch([
    'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerEscapes.mp4',
    'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
  ])
  .then((state) => {
    // use the promise or the onComplete event
    console.log('resolved', state)
  })

preloader.onComplete((state) => {
  console.log('completed', state)
})

preloader.onProgress((event) => {
  // use Math.round() if you want integers only
  console.log(event.progress + '%')
})

preloader.onFetched((state) => {
  console.log('fetched', state)
})

preloader.onError((state) => {
  console.log('error', state)
})

Examples

Canceling

The asset preloader can be canceled at any time during loading, when calling preload.cancel() all assets already preloaded will be available for use, but the download of pending assets will be abandoned and status will be set to 0.

preload.onCancel((items) => {
  console.log(items)
})

preload.cancel()

Keywords

FAQs

Package last updated on 26 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc