For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt, and this page is available as Markdown at /next/api/lynx-api/lynx/lynx-cancel-resource-prefetch.md.
Lynx
  • English
  • lynx: cancelResourcePrefetch() static method

    Syntax

    cancelResourcePrefetch(data: object, callback: (res: object) => void) : void;

    Parameters

    data

    A collection that describes the details of all resources to be canceled for preloading, with its keys defined as follows:

    • data: Type array, each item inside the array corresponds to a resource. The keys for each item are defined as follows:
      • uri: Type string, represents the CDN address of the resource.
      • type: Type string, represents the type of resource. The supported resource types are defined as follows:
        • video: Audio/video resources (preloading cancellation for image and font resources is currently not supported)
      • params: Custom control parameters for canceling preloading, the supported parameters are as follows:
        • preloadKey: Only for video type resources. Represents a unique key that identifies the resource. It is necessary to ensure that the preloadKey passed here is consistent with that used when calling requestResourcePrefetch. This is a required parameter.

    callback

    The callback function that is called after the API execution is completed or fails. The structure of its return parameters is as follows:

    • code: Type number, status code, which may take the following values:
      • 0: Success
      • 11001: Parameter error
    • msg: Type string, a global error message
    • details: Type array, where each detail represents the cancelation status details of a resource. The structure of each detail is as follows:
      • code: Type number, status code, which may take the following values:
        • 0: Success
        • 11001: Parameter error
      • msg: Type string, error message
      • uri: Type string, represents the CDN address of the resource.
      • type: Type string, represents the type of the resource, defined as follows:
        • video: Audio/video resources

    Return Value

    None (undefined).

    Exceptions

    • When there is a parameter error, code will return the 11001 error code, and the msg will contain detailed error information.

    Example

    import { useEffect } from '@lynx-js/react';
    
    function Page() {
      // We need to preload two videos.
      // First, prepare the resource parameters, assigning the necessary preloadKey to the videos.
      let resData = [
        {
          uri: 'https://zzzzz1.mp4',
          type: 'video',
          params: { preloadKey: 'zzzzz1' },
        },
        {
          uri: 'https://zzzzz2.mp4',
          type: 'video',
          params: { preloadKey: 'zzzzz2' },
        },
      ];
    
      useEffect(() => {
        // Call requestResourcePrefetch to initiate preloading
        lynx.requestResourcePrefetch?.(
          {
            data: resData,
          },
          (res) => {
            if (res.code == 0) {
              console.log('success!');
            } else {
              console.log('fail! ', res.msg);
            }
            console.log(
              'prefetch status of each resource:',
              JSON.stringify(res.details),
            );
          },
        );
      }, []);
    
      const handleTap = () => {
        // Trigger the cancellation of resource preloading on click
        // Call cancelResourcePrefetch to cancel the preloading
        lynx.cancelResourcePrefetch?.(
          {
            data: resData,
          },
          (res) => {
            if (res.code == 0) {
              console.log('success!');
            } else {
              console.log('fail! ', res.msg);
            }
            console.log(
              'cancel status of each resource:',
              JSON.stringify(res.details),
            );
          },
        );
      };
    
      return <view onTap={handleTap}>{/* ... */}</view>;
    }
    
    export default Page;

    Compatibility

    LCD tables only load in the browser

    Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.