Socket
Book a DemoInstallSign in
Socket

@okiba/resource-loader

Package Overview
Dependencies
Maintainers
3
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@okiba/resource-loader

Class to fetch resources, prefers a separate thread

latest
Source
npmnpm
Version
0.1.25
Version published
Maintainers
3
Created
Source

Okiba / ResourceLoader

Manages loading of resources trough fetch to boost caching. Transparently relies on a WebWorker if possible to load on a separate thread.

__

import ResourceLoader from '@okiba/resource-loader'

const resLoader = new ResourceLoader()

// if `window.Worker` is available
// `fetch` happens on a separate thread!

urls.forEach(
  url => resLoader.load(url)
    .then(console.log('Loaded! 📦'))
    .catch(console.log('Fail! ☹️'))
)

Installation

npm i --save @okiba/resource-loader

Or import it directly in the browser

<script type="module" src="https://unpkg.com/@okiba/resource-loader/index.js"></script>

Usage

import ResourceLoader from '@okiba/resource-loader'

Untranspiled code 🛑

Okiba Core packages are not transpiled, so don't forget to transpile them with your favourite bundler. For example, using Babel with Webpack, you should prevent imports from okiba to be excluded from transpilation, like follows:

{
  test: /\.js$/,
  exclude: /node_modules\/(?!(@okiba)\/).*/,
  use: {
    loader: 'babel-loader',
    options: {
      presets: ['@babel/preset-env']
    }
  }
}

Todo:

  • Handle abortion
  • Fetch is not on IE11
  • Clone response and pass it as promise reslult

load(url)

Initiates loading of a resource at a given URL

Arguments

+ url: String

Resource URL

Returns

Promise A promise which will be resolved if the resource is loaded and rejected if not.

Keywords

okiba

FAQs

Package last updated on 26 May 2020

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