lynx: requestResourcePrefetch() static method
- This API is used for proactively initiating the preloading of CDN resources from the frontend, currently supporting image, video, audio, and font resource types.
- The preloaded resources will not be returned to the frontend through this API; instead, they are retained in memory or on disk. Therefore, after preloading is complete, a
unique keyis needed to specify the resource to the component:- The key for an image resource is consistent with the
uriparameter during its preloading. When rendering, pass this key to the src attribute of the<image />component, allowing the component to locate the resource.
- The key for an image resource is consistent with the
Syntax
Parameters
data
A collection that describes all the details of the resources to be preloaded, its keys are defined as follows:
data: Typearray, each item inside the array corresponds to a resource. The keys for each item are defined as follows:uri: Typestring, represents the CDN address of the resource.type: Typestring, represents the type of resource. The defined types of resources are as follows:image: Image resource. (api/elements/built-in/image.html#trailnewimage--) switch for the Image component to preload images.)video: Video resource.audio: Audio resource.font: Font resource.
params(optional): Custom control parameters for resource preloading, the supported parameters are as follows:priority(optional): Only forimagetype resources. Indicates network request priority. If the priority is high, other image requests will be blocked while the image library preloads these images, which may slow down the display of other images. Therefore, if these preloaded images are not immediately needed for display, consider setting a lower priority. The options supported are as follows:high: High priority.medium: Medium priority.low: Low priority, this is the default value.
cacheTarget(optional): Only forimagetype resources. Indicates the form in which resources are saved. The options supported are as follows:disk: Resource is saved to disk after preloading is completed, this is the default value.bitmap: Resource is decoded into a bitmap and saved in memory after preloading. (Note: Currently, Android bitmap caching is not yet effective.)
preloadKey: Only forvideo,audiotype resources. Represents a unique key that identifies the resource. When rendering the <x-video-pro> component, this key must be specified so that the component can find the preloaded cache. This is a required parameter.size(optional): Only forvideotype resources. Indicates the size of the preload, with a default value of 500 * 1024 (bytes).
callback
The callback function called after the API is executed or fails. The inside definition of its parameters is as follows:
code: Typenumber, status code, which may take the following values:0: Success.32101: Parameter error.32102: Image prefetch helper does not exist.32103: Resource service does not exist.32104: Timed out while waiting for prefetch completion. This is only possible whenconfig.awaitComplete = true.
msg: Typestring, a global error message.details: Typearray, where each detail represents the preload status details of a resource, with the internal definition of detail as follows:code: Typenumber, status code, which may take the following values:0: Success.32101: Parameter error.32102: Image prefetch helper does not exist.32103: Resource service does not exist.
msg: Typestring, error message.uri: Typestring, represents the CDN address of the resource.type: Typestring, represents the type of the resource, with resource types defined as follows:image: Image resource.video: Video resource.audio: Audio resource.font: Font resource.
config (since 3.9)
Controls whether the callback waits for prefetch completion and how long it waits:
awaitComplete(optional): Typeboolean, defaultfalse. When set totrue, thecallbackis invoked only after all resources complete prefetching; if the wait times out, the API returns32104.awaitTimeout(optional): Typenumber, in milliseconds, default60000. This only takes effect whenawaitComplete = true.
Return Value
None (undefined).
Errors
- When there is a parameter error, the
codereturns32101, and themsgcontains detailed error information. - When the Image prefetch helper does not exist, the
codereturns32102. - When the Resource service does not exist, the
codereturns32103. - When
awaitCompleteis enabled and waiting times out, thecodereturns32104.
Example
Compatibility
LCD tables only load in the browser