Universal resource loading (browser and Node.js) designed to work with HTML5 Canvas and WebGL. Supports loading text, JSON, binary and images (using custom loaders). The API interface for getres is heavily inspired by that of resl, differing mainly in the ability to run in Node.js as well as the browser.
getres is lightweight and compatible with IE9+ and all other modern browsers with support for promises optional.
var getres =
This example uses ES5 and traditional callbacks. See further down the README for more examples which include: loading multiple resources; loading arrays; objects and nested resources; using the parser function; use of promises; and hooking into progress events.
yarn add getres
You can use getres with or without promises. First without:
Now with promises:
/* Or with progress listener */
object where the keys correspond to the name of each resource and the value is itself an object with the following properties or key(s) for nested resources:
||Resource URL(s) to load. Can be a
To use promises you must ensure the environment supports these already. For some older browsers you may need to use a suitable polyfill. Alternatively you can also set your own promise library with
getres.Promise = require('bluebird') (swap Bluebird for your library of choice).
All of these examples use ES6 syntax which may require transpilation to work across browsers.
Kitchen sink example
In one giant ball of
config this demonstrates most of the functionality of getres including:
- Loading different resource types:
- Using a
parserfunction to transform the resource.
- Hooking into individual resource loading with the
- Accessing the
resourcetree using promises instead of callbacks.
- Hooking into progress events.
// TODO: LOADER!getres
Source array example
Source object example
Sync and async parser
Register custom loader
getres was created after trying and failing to get resl working across Node.js and the browser, with a view to using it headlessly with the excellent regl WebGL library and headless-gl. So, the API resemblance between both libraries is strong. Thanks to mikolalysenko and contributors for all of the above.
getres uses superagent behind the scenes to make HTTP requests.