Newer Version Available

This content describes an older version of this product. View Latest

Foreground and Background Actions

Actions run in the foreground by default. You can set an action to run in the background. This feature is useful if you want your app to remain responsive to a user while it executes a low priority, long-running action. A rough guideline is to use a background action if it takes more than a few seconds for the response to return from the server.

When enqueued actions are grouped into boxcars and sent to the server, foreground actions are processed first, followed by background actions. Don’t rely on each background action being sent in its own request as that behavior isn’t guaranteed. On the server, foreground actions run in parallel with background actions, and responses for foreground and background actions can come back in either order.

Framework-Managed Request Throttling

The framework manages and enqueues foreground and background requests separately. This means that the framework can control the number of foreground requests and the number of background actions running at any time. The framework automatically throttles the rate of sending these requests. Other than setting an action to run in the background, you can’t control the framework’s request processing. The framework manages the number of foreground and background XHRs, which varies depending on available resources and the boxcar’ing strategy enabled in your org.

Even with separate throttling, background actions can affect performance in some conditions, such as when there is an excessive number of requests to the server.

Setting Background Actions

To set an action as a background action, call the setBackground() method on the action object in JavaScript.

1// create a server-side action
2var action = cmp.get("c.serverEcho");
3
4// optionally set actions params
5// action.setParams({ firstName : cmp.get("v.firstName") });
6
7// set as a background action
8action.setBackground();

A background action can’t be set back to a foreground action. setBackground takes no arguments, and calling setBackground more than once has no effect.

Note