Git Product home page Git Product logo

brunopiaui / preload-it-extended Goto Github PK

View Code? Open in Web Editor NEW

This project forked from andreupifarre/preload-it

0.0 1.0 0.0 2.31 MB

A tiny 1kb JavaScript library for preloading assets on the browser via XHR2. It provides the ability to load assets of different file types and composite progress events.

Home Page: https://andreupifarre.github.io/preload-it/docs/index.html

License: MIT License

JavaScript 91.73% HTML 8.27%

preload-it-extended's Introduction

preload-it-extended

This lib is a fork of the project preload-it.

A tiny 1kb JavaScript library for preloading assets on the browser via XHR2. It provides the ability to preload assets of different file types and composite progress events.

Installing

If you use npm, npm i preload-it-extended. Otherwise, download the latest release. The released bundle supports anonymous AMD, CommonJS, and vanilla environments. You can load directly from unpkg. For example:

<script src="https://unpkg.com/preload-it-extended@latest/dist/preload-it-extended.js"></script>

For the minified version:

<script src="https://unpkg.com/preload-it-extended"></script>

preload-it-extended is written using ES2015 modules. To import preload-it-extended into an ES2015 application, import into a namespace:

<script type="module">
  import preload from "https://unpkg.com/preload-it-extended@latest/dist/preload-it-extended.esm.min.js";
</script>

or

import Preload from "preload-it-extended";
const preload = Preload();

Getting started

const preload = Preload();

preload
  .fetch([
    "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerEscapes.mp4",
    "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4",
    "https://images.pexels.com/photos/248797/pexels-photo-248797.jpeg"
  ])
  .then(items => {
    // use either a promise or 'oncomplete'
    console.log(items);
  });

preload.oncomplete = items => {
  console.log(items);
};

preload.onprogress = event => {
  console.log(event.progress + "%");
};

preload.onfetched = item => {
  console.log(item);
};

preload.onerror = item => {
  console.log(item);
};

Canceling preload of assets

Preloading of assets can be canceled at any time during fetching, when calling preload.cancel() all assets already preloaded will be available to use, however the download of pending assets will be abandoned, and status will be set to 0 for those remaining items.

preload.cancel();

preload.oncancel = items => {
  console.log(items);
};

License

Released for free under the MIT license, which means you can use it for almost any purpose (including commercial projects). We appreciate credit where possible, but it is not a requirement.

MIT.

preload-it-extended's People

Contributors

andreupifarre avatar brunopiaui avatar drpepper avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.