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
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. |
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
Create a new resource loader.
Properties
type
|
String |
readonly
|
Template string to be used as a part to be replaced by the callback function name when calling JSONP.
|
Methods
Create a promise object that loads your app.
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. |
Create a promise object that loads your app.
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. |
Create a promise object that loads specific JavaScript.
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. |
Create a promise object that loads specific JavaScript.
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. |
Create a promise object that loads CSS.
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. |
Create a promise object that loads CSS.
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. |
Create a promise object that loads data using the JSONP protocol.
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. |
Create a promise object that loads data using the JSONP protocol.
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. |
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.
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. |
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.
name |
type |
description |
resolver
|
(appId: String)=>String |
App URL resolver function. |
Add the app to load.
name |
type |
description |
appURI
|
String |
ID of the app to load. After the ID, search parameters or hashes may be included. |
Add the app to load.
name |
type |
description |
appURL
|
URL |
The URL of the app to load. This URL must be in the form of a relative path URI. |
Add CSS as a resource to load.
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. |
Add CSS as a resource to load.
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. |
Add data loading using the JSONP protocol.
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. |
Add data loading using the JSONP protocol.
return
|
ResourceLoader |
Promise object that delivers the result value of JSONP of the URL. |
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.
name |
type |
description |
moduleId
|
String |
The id of the Module to add. |
Add a script to load.
name |
type |
description |
uri
|
String |
Script to load src |
integrityOptionoptional
|
CodeIntegrityOption |
Code security options. |
Add a script to load.
name |
type |
description |
url
|
URL |
Script src URL to load |
integrityOptionoptional
|
CodeIntegrityOption |
Code security options. |
Prepare all resources and perform the given procedure once ready.
If all resources are already ready, the given procedure is performed immediately.
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. |
Returns whether a resource load request exists that requires loading from the resource loader.