Resource Loader
A generic resource loader, made with web games in mind.
Philosophy
This library was built to make it easier to load and prepare data asynchronously. The
goal was mainly to unify the many different APIs browsers expose for loading data and
smooth the differences between versions and vendors.
It is not a goal of this library to be a resource caching and management system,
just a loader. This library is for the actual mechanism of loading data. All
caching, resource management, knowing what is loaded and what isn't, deciding
what to load, etc, should all exist as logic outside of this library.
As a more concrete statement, your project should have a Resource Manager that
stores resources and manages data lifetime. When it decides something needs to be
loaded from a remote source, only then does it create a loader and load them.
Usage
import { Loader } from 'resource-loader';
const loader = new Loader();
loader
.add(url)
.use((resource, next) =>
{
next();
})
.load((loader, resources) => {
});
loader.onStart.add(() => {});
loader.onError.add(() => {});
loader.onLoad.add(() => {});
loader.onProgress.add(() => {});
loader.onComplete.add(() => {});
Building
You will need to have node setup on your machine.
Then you can install dependencies and build:
npm i && npm run build
That will output the built distributables to ./dist
.
Supported Browsers
- IE 9+
- FF 13+
- Chrome 20+
- Safari 6+
- Opera 12.1+
Upgrading to v4
- Before middleware has been removed, so no more
pre
function.
- If you used
pre
middleware for url parsing, use the new urlResolver
property instead.
crossOrigin
must now be a string if specified.Resource.LOAD_TYPE
enum replaced with Load Strategies.
- For example,
loadType: Resource.LOAD_TYPE.IMAGE
is now strategy: Loader.ImageLoadStrategy
.
Resource.XHR_RESPONSE_TYPE
enum replaced with XhrLoadStrategy.ResponseType
.
- For example,
xhrType: Resource.XHR_RESPONSE_TYPE.DOCUMENT
is now xhrType: Loader.XhrLoadStrategy.ResponseType.Document
.
- Overloads for the
add
function have been simplified.
- The removed overloads were not widely used. See the docs for what is now valid.