cpr.core.ResourceLoader

The resource loader loads and prepares specific apps, external scripts, CSS resources, and data via the JSONP protocol, and then helps you run the code.

Index

Properties
Name Type Description
JSONP_CALLBACK_TEMPLATE String Template string to be used as a part to be replaced by the callback function name when calling JSONP.
Methods
Name Return Type Description
loadApp Promise<cpr.core.App> Create a promise object that loads your app.
loadScript Promise<HTMLScriptElement> Create a promise object that loads specific JavaScript.
loadCSS Promise<StyleSheet> Create a promise object that loads CSS.
loadJsonp Promise<Object> Create a promise object that loads data using the JSONP protocol.
setQueryProvider Specifies a query provider function that can add additional search parameters to resource URLs to be loaded through the resource loader.
setAppURLResolver Register an app URL resolver that can personalize the URL of the actual compiled js file based on the requested App ID.
addApp ResourceLoader Add the app to load.
addCSS ResourceLoader Add CSS as a resource to load.
addJsonp ResourceLoader Add data loading using the JSONP protocol.
addModule ResourceLoader Add a Module as a resource to load.
addScript ResourceLoader Add a script to load.
load Promise<Array> Prepare all resources and perform the given procedure once ready.
needToLoad Boolean Returns whether a resource load request exists that requires loading from the resource loader.

Constructor

ResourceLoader()
Create a new resource loader.

Properties

JSONP_CALLBACK_TEMPLATE
type String
readonly
Template string to be used as a part to be replaced by the callback function name when calling JSONP.

Methods

loadApp(appURL)
Create a promise object that loads your app.
Parameters
name type description
appURL URL The URL of the app to load. This URL must be in relative URI format.
return Promise<cpr.core.App> Promise object passing the loaded app.
loadApp(appURI)
Create a promise object that loads your app.
Parameters
name type description
appURI String ID of the app to load. After the ID, search parameters or hashes may be included.
return Promise<cpr.core.App> Promise object passing the loaded app.
loadScript(uri, integrityOption)
Create a promise object that loads specific JavaScript.
Parameters
name type description
uri String The URI string of the JavaScript to load.
integrityOptionoptional CodeIntegrityOption Code security options.
return Promise<HTMLScriptElement> Promise object that supplies loaded JavaScript HTML script elements.
loadScript(url, integrityOption)
Create a promise object that loads specific JavaScript.
Parameters
name type description
url URL The URL of the JavaScript to be loaded.
integrityOptionoptional CodeIntegrityOption Code security options.
return Promise<HTMLScriptElement> Promise object that supplies loaded JavaScript HTML script elements.
loadCSS(uri, integrityOption)
Create a promise object that loads CSS.
Parameters
name type description
uri String The uri of the CSS to load.
integrityOptionoptional CodeIntegrityOption Code security options.
return Promise<StyleSheet> Promise object that supplies the loaded stylesheet.
loadCSS(url, integrityOption)
Create a promise object that loads CSS.
Parameters
name type description
url URL The URL of the CSS to load.
integrityOptionoptional CodeIntegrityOption Code security options.
return Promise<StyleSheet> Promise object that supplies the loaded stylesheet.
loadJsonp(uri, option)
Create a promise object that loads data using the JSONP protocol.
Parameters
name type description
uri String JSONP service URL. Please specify the location of the name of the callback function by inserting the __callback__ keyword inside the URL. If keywords are omitted, it is assumed that callback search parameters are used. Example: http://url.com/?callback=__callback__
optionoptional CodeIntegrityOption Code security options.
return Promise<Object> Promise object that delivers the result value of JSONP of the URL.
loadJsonp(url, integrityOption)
Create a promise object that loads data using the JSONP protocol.
Parameters
name type description
url URL JSONP service URL. Please specify the location of the name of the callback function by inserting the __callback__ keyword inside the URL. If keywords are omitted, it is assumed that callback search parameters are used. Example: http://url.com/?callback=__callback__
integrityOptionoptional CodeIntegrityOption Code security options.
return Promise<Object> Promise object that delivers the result value of JSONP of the URL.
setQueryProvider(queryProvider)
Specifies a query provider function that can add additional search parameters to resource URLs to be loaded through the resource loader. The provider function receives the original URL and whether to use the cache as arguments and must return a JSON object containing the key/value to be added to the query. The query provider may supply additional keys if app caching is not allowed, but must include all keys provided if app caching is allowed. If a query provider that does not meet this condition is specified, an exception is raised. If you specify null as the provider function, it will operate as the system default behavior. The system default behavior is to add a random number, such as `?p=0.3141592`, as the p query key to every resource request when no cache is specified.
Parameters
name type description
queryProvider (originURL: cpr.utils.URL, allowsCache: Boolean)=>{[key:string]: String} Query provider. It receives the original URL and whether to allow app cache as arguments.
setAppURLResolver(resolver)
Register an app URL resolver that can personalize the URL of the actual compiled js file based on the requested App ID. The default resolver returns `./${AppID}.clx.js`. If the user's app URL resolver has no return value or returns null, the default resolver will be used instead.
Parameters
name type description
resolver (appId: String)=>String App URL resolver function.
addApp(appURI)
Add the app to load.
Parameters
name type description
appURI String ID of the app to load. After the ID, search parameters or hashes may be included.
return ResourceLoader
addApp(appURL)
Add the app to load.
Parameters
name type description
appURL URL The URL of the app to load. This URL must be in the form of a relative path URI.
return ResourceLoader
addCSS(uri, wait, integrityOption)
Add CSS as a resource to load.
Parameters
name type description
uri String Css URI to add.
waitoptional Boolean Waiting or not. Wait for CSS to load only when this value is true.
integrityOptionoptional CodeIntegrityOption Code security options.
return ResourceLoader
addCSS(url, wait, integrityOption)
Add CSS as a resource to load.
Parameters
name type description
url URL The css URL to add.
waitoptional Boolean Waiting or not. Wait for CSS to load only when this value is true.
integrityOptionoptional CodeIntegrityOption Code security options.
return ResourceLoader
addJsonp(uri, integrityOption)
Add data loading using the JSONP protocol.
Parameters
name type description
uri String JSONP service URI string. Please specify the location of the name of the callback function by inserting the __callback__ keyword inside the URL. If keywords are omitted, it is assumed that callback search parameters are used. Example: http://url.com/?callback=__callback__
integrityOptionoptional CodeIntegrityOption Code security options.
return ResourceLoader Promise object that delivers the result value of JSONP of the URL.
addJsonp(url, integrityOption)
Add data loading using the JSONP protocol.
Parameters
name type description
url URL
integrityOptionoptional CodeIntegrityOption Code security options.
return ResourceLoader Promise object that delivers the result value of JSONP of the URL.
addModule(moduleId)
deprecatedAll common modules are compiled into a single file and pre-prepared, so this API is not necessary.
Add a Module as a resource to load.
Parameters
name type description
moduleId String The id of the Module to add.
return ResourceLoader
addScript(uri, integrityOption)
Add a script to load.
Parameters
name type description
uri String Script to load src
integrityOptionoptional CodeIntegrityOption Code security options.
return ResourceLoader
addScript(url, integrityOption)
Add a script to load.
Parameters
name type description
url URL Script src URL to load
integrityOptionoptional CodeIntegrityOption Code security options.
return ResourceLoader
load(doneHandler)
Prepare all resources and perform the given procedure once ready. If all resources are already ready, the given procedure is performed immediately.
Parameters
name type description
doneHandleroptional (error: Error)=>Void defaultnull Procedure to run after all resources are ready. The error object is passed as an argument.
return Promise<Array> Promise context where all resources are prepared.
needToLoad()
Returns whether a resource load request exists that requires loading from the resource loader.
return Boolean