- Print
- DarkLight
- PDF
Description
Initiates an asynchronous download of a specified resource from your app's locker.
When downloading completes, the resource is stored inside the runtime's cache object using the resource's locker token as a key. An alternative key can be specified, if desired.
The Ux.ResourceReady event is triggered so you can take action when your resource becomes available.
Input Parameters
Name | Type | Required | Description |
---|---|---|---|
token | Text | Yes | Resource's locker token |
[key] | Text | No | Unique cache key where resource will be stored; Default = resource's locker token |
[type] | Text | No | Type of data being downloaded |
The following types are supported:
Name | Description |
---|---|
text | Plain text (default) |
json | Json object |
xml | Xml document |
image | Platform-specific image object |
bits | Raw binary data |
Returns
No return value.
Examples
// inside the Ux.Initialize script...
// download resource from app's locker
app.locker.download("TOKEN");
// inside the Ux.Initialize script...
// download resource from app's locker, specifying a custom cache key
app.locker.download("TOKEN", "config");
// inside the Ux.ResourceReady script...
// note: this script will run once for each downloaded resource
// note: demonstrates how to take action immediately after download completes
// get the cache key for this downloaded resource
var key = script.args[0];
// fetch the downloaded resource from cache
var item = cache.get(key);
// inside any script (i.e. Ux.Change)...
// note: demonstrates how to manually check for resource anytime
// check if resource is available
if (cache.exists("TOKEN") === true)
debug.log("Resource exists.");
Remarks
Use this function when you need to download resources from your app's locker such as files, configurations, lookup tables, raw data, or images.
Downloading resources from your app's locker instead of the open Internet is strongly recommended since they are fully managed by the app platform.
One common scenario is to download a file using the Ux.Initialize event. Once downloaded, you can take action using the Ux.ResourceReady event. The cache key you provided is accessible via the runtime's script object.
Downloading resources can be slow based on connection speeds and the size of the resources being downloaded.
Because of this speed issue, downloading resources requires a two-step process. First, you must initiate the download (from one script). Second, you take action (if needed) after the download completes from another script (i.e. Ux.ResourceReady).
By separating these steps, the user's experience remains fluid. Otherwise, the user interface would freeze until the download completes, resulting in a poor user experience.