- Resource declaration
interface Resource {
type:String; // type name js|css
urls:String[];
serial?:Boolean; // if serial load urls
dependence?:Resource; // will be load before load urls
timeout?:number // timeout of every url item load | ms
}
- parallel load resource urls
var resource = {
type:'js',
urls:['test/a.js']
};
- serial load resource urls
var resource = {
type:'js',
serial:true,
urls:['test/a.js']
};
- with dependence
var resource = {
type:'js',
urls:['test/a.js'],
dependence:{
type:'js',
urls:['test/b.js']
}
};
// load: b.js --> a.js
- css resource
var resource = {
type:'css',
timeout:2000,
urls:['test/a.css']
};
- text resource
var resource = {
type:'text',
timeout:2000,
urls:['test/a.html']
};
- json resource
var resource = {
type:'json',
timeout:2000,
urls:['test/a.json']
};
- image resource
var resource = {
type:'image',
timeout:2000,
urls:['test/a.image']
};
- Define ResourceLoader
interface ResourceLoaderOption {
baseURI?:String; // Define load baseURI
useCache?:Boolean; // if use Cache
params?:Object // url query params
timeout?:number; //timeout of all loaders
}
var loader = new HERE.ResourceLoader({
baseURI:'../',
timeout:8000 // timeout of all request
});
- Start load Resource
var promise = loader.load(resource);
promise.then(function(){
console.log('load finished !');
},function(){
console.log('load error or timeout !');
});
//other resource,will load resourceCss after resourceJs has been loaded
var resourceJs,resourceCss;
loader.load(resourceJs,resourceCss);
// parallel load resource,you can
loader.load([resourceJs,resourceCss]);
// mixed serial load and parallel load,
//load resourceC after resourceJs and resourceCss has been loaded,resourceJs and resourceCss load parallel
var resourceC;
loader.load([resourceJs,resourceCss],resourceC);
- Extend loader for ResourceLoader
ResourceLoader.registerLoader(type:String,loader:Loader);