lynx: requestResourcePrefetch() static method
- This API is used for proactively initiating the preloading of CDN resources from the frontend, currently supporting only image, video, and audio 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.
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.11001: Parameter error.
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.11001: Parameter error.
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.
Return Value
None (undefined).
Errors
- When there is a parameter error, the
codewill return the11001error code, and themsgwill contain detailed error information.
Example
Compatibility
LCD tables only load in the browser