Introduction

Getting started

Walkthrough Guides

CafeX Apps

Workflows

Using CafeX Collaborate App

Reporting

Managing CafeX

Integrating CafeX

Security

App Studio

App Studio Components

How-tos

How-tos

Configuring Image Fetching

Modified on Wed, 5 Mar at 7:15 AM

TABLE OF CONTENTS


Image Fetching enhances user experience by ensuring that images are available instantly when needed, reducing load times. This article outlines the steps to implement image preloading.


How It Works

The fetching mechanism ensures seamless transitions between tasks by loading images in the background before they are needed. The process follows these key steps:

  1. When the user initiates an action (e.g., clicking a button), the app determines which images are required for the next task.

  2. A hidden Container Component preloads images in the background while users interact with the current content.

  3. When needed, preloaded images are fetched from the data sets and displayed immediately, preventing noticeable load times.

  4. Event handlers detect user actions (e.g., button clicks) and update the displayed images dynamically.

  5. UI components, such as Cards and Images, retrieve and render preloaded content.

Configuration Steps

The image fetching configuration consists of:

  1. Creating Data sets.
  2. Adding UI Components. 
  3. Adding Event Handlers.


Step 1: Create Data sets

To fetch images, we first need to define Data sets.

To add a Data set:

  1. Under Explorer and Components > Explorer, click App.
  2. Under Appearance and Configuration > Configuration, locate the Data sets section. 
  3. Click Add data set and enter the suggested values for each Data set:

    Images Collection Data set

    This data set manages images using JavaScript.

    SettingValue
    NameImages Collection
    TypeJavascript
    Evaluate automaticallyEnabled
    OutputOutput data type: Object
    Array: Enabled

    Click Add field:
    Data type: Object
    Name: Images
    Array: Enabled

    Hover over the newly added field and click the plus icon (+):
    Data type: Text
    Name: img
    Array: Disabled
    Code
    return [
      { Images: [
          {img: "https://picsum.photos/id/237/200/300"},
          {img: "https://picsum.photos/id/17/2500/1667"},
          {img: "https://picsum.photos/id/28/4928/3264"},
          {img: "https://picsum.photos/id/35/2758/3622"}
        ]
      },
      { Images: [
          {img: "https://picsum.photos/id/9/5000/3269"},
          {img: "https://picsum.photos/id/13/2500/1667"}
        ]
      },
      { Images: [
          {img: "https://picsum.photos/id/21/3008/2008"},
          {img: "https://picsum.photos/id/36/4179/2790"},
          {img: "https://picsum.photos/id/40/4106/2806"},
          {img: "https://picsum.photos/id/42/3456/2304"}
        ]
      },
      { Images: [
          {img: "https://picsum.photos/id/50/4608/3072"},
          {img: "https://picsum.photos/id/76/4912/3264"},
          {img: "https://picsum.photos/id/63/5000/2813"},
          {img: "https://picsum.photos/id/73/5000/3333"}
        ]
      },
      { Images: [
          {img: "https://picsum.photos/id/75/1999/2998"},
          {img: "https://picsum.photos/id/82/1500/997"},
          {img: "https://picsum.photos/id/84/1280/848"}
        ]
      }
    ];
                        

    Images Data set

    This data set stores available images.

    SettingValue
    NameImages
    TypeVariable
    Expression{{{Images Collection}}}
    Evaluate automaticallyEnabled

    Next Images Data set

    This data set contains the next set of images to be displayed when transitioning between tasks.

    SettingValue
    NameNext Images
    TypeJavascript
    Evaluate automaticallyDisabled
    InputData set: Images
    Required: Enabled
    OutputOutput data type: Text
    Array: Disabled
    Code
    return inputs["Images"].slice(1)

    Image Set Current Data set

    This data set holds the images currently displayed on the screen.

    SettingValue
    NameImage Set Current
    TypeJavascript
    Evaluate automaticallyEnabled
    InputData set: Images
    Required: Enabled
    OutputOutput data type: Object
    Array: Disabled
    Code
    return inputs["Images"][0];

    Image Set Next Data set

    This data set preloads images for the next task.

    SettingValue
    NameImage Set Next
    TypeJavascript
    Evaluate automaticallyEnabled
    InputData set: Images
    Required: Enabled
    OutputOutput data type: Object
    Array: Disabled

    Click Add field, then click the Edit icon:
    Data type: Object
    Name: Images
    Array: Enabled

    Hover over the newly added field and click the plus icon (+):
    Data type: Text
    Name: img
    Array: Disabled
    Code
    return inputs["Images"][1];


Step 2: Add UI Components

In this step, we'll add the required UI components to the App:

  • (1) Add the Container Component (Containers > Container). This component will be used for preloading images in the background.
    • Inside the Container Component, add the Box component (Graphical > Box) for structure.
    • Inside the Container Component, add the Card Component (Data > Card) with the following  Configuration:

      SettingValue
      Data setImage Set Next
      Data pathImages
      • Inside the Card Component, add the Image Component:

        SettingValue
        Data setCard card data (from the enclosing card)
        Data pathimg
    • Inside the Container Component, add the Image Component.

      Go back to the Container Component's configuration and set Size & position to X:10, Y:5, W:1, H:1 which keeps the Component small but active for the browser.
  • (2) Add the Button Component. This button will update the images when clicked.
  • (3) Add the Card Component (Data > Card). This component will display the current image/images.
    SettingValue
    Data setImage Set Current
    Data pathImages
    • Inside the Card Component, add another Image component with the following Configuration:

      SettingValue
      Data setCard card data (from the enclosing card)
      Data pathimg

Step 3: Add Event Handlers

The Button component's configuration consists of the following event handlers, which should be configured in the same order as listed below:

1. Load Next Images

This event handler retrieves the next set of images by evaluating the Next Images data set when the button is clicked.

SettingValue
Handler NameLoad Next Images
Event TypeClick
ActionEvaluate a data set
Data SetNext Images
Wait for ResponseEnabled
Continue on ErrorDisabled


2. Update Images

This event handler updates the displayed images by setting the Images variable to the value retrieved from the Next Images data set.

SettingValue
Handler NameUpdate Images
Event TypeClick
ActionSet a variable
Variable to SetImages
Value to Set{{{Next Images}}}

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article