Have you ever had the headache of not knowing when you can upgrade to the latest applets? Curious about the convergence rate of small packages? Is there any trace of all this? Today we’re going to cut through the fog and explore the existing mechanics of applet updates

background

The distribution and installation of small program package relies on Baidu App, which has the characteristics of high distribution efficiency and fast installation. However, like traditional App, small program package still has some problems such as version convergence rate. Because the applets update asynchronously, some users cannot immediately use the latest version when they start the applets the next time.

One pain point that often confuses developers is: When can users upgrade to the latest applets? And how fast do small packages converge?

In order to facilitate the subsequent elaboration of the content, first of all, the startup mode of the small program is simply explained:

Cold start

Cold start of applets is triggered when:

  • When the applet is first opened;
  • Switch the background of the small program automatically destroyed after opening again;
  • When the number of active applets reaches a certain level (currently 6), open new applets again.

The applet on cold startup loads the page and the applet related resources are reloaded.

Warm start

When the mini program switches to the background (triggered by the mobile phone’s physical back button or the close button on the upper right of the mini program), it will not be destroyed immediately, but will wait for a certain period of time (currently 5 minutes) before it is destroyed automatically. If the user again at this time, the small program will not reload, but the background small program wake up to the foreground, this trigger is hot start.

Design ideas

The update mechanism of the small program package should be a comprehensive measure: on the one hand, the convergence speed of the small program package should be taken into account; on the other hand, the number of downloading and installing the small program package should be reduced as much as possible.

The startup and first-screen performance of small programs directly affect user experience, and the download and installation of small programs is a time-consuming step in the startup process. Therefore, the design idea of the update mechanism of the existing small program package is to find a compromise scheme that can take care of the convergence speed of the small program package and avoid downloading and installing every time it is started.

The existing mechanisms

  1. Cold start of small program package Asynchronous update: When the small program is cold start, it asynchronously checks whether the cloud has updated the small program package and downloads and installs the small program. It takes effect the next time the small program is cold started.

  2. MaxAge small package failed: Similar to the working principle of cookie maxAge, the validity period of locally downloaded small program packages on Baidu App is controlled by maxAge (the maxAge value is cloud-controlled, currently 5 days). The start time of each maxAge computing cycle is the time when the latest downloaded and updated small program packages are updated. If the local small program packages have expired, When the second small program is started, the status of the cloud small program package will be synchronously queried. When there is an update at this time, the small program will continue to wait for the completion of the download of the small program before opening the small program. MaxAge method can ensure that the time of the developer’s latest small program package is marked as T, and the small program package can effectively converge to a higher level within (T+maxAge).

  3. Idle time Update: added small program idle time scene coverage

Typical scenarios: small program entrance on the second floor of the home page, user personal center entrance, Feed cards, etc.

Update the small program package in advance before opening the small program so as to solve the convergence rate problem of asynchronous loading of small program package to a certain extent. This approach is a useful complement to the asynchronous update and maxAge approach.

  1. Mark update: uniformly mark the update status of the applets currently used by the user, and determine the list of applets that need to be updated.

For example, when the Baidu App host pulls the configuration at each cold start, it marks the update status of the small program used by the current user. The list marked as needing to be updated can trigger the update of the applet package through the idle update mode; For applets that do not need to update the package, the request to wait synchronously to query the update status of the applets when maxAge expires can be optimized.

  1. Other methods, such as: using the long connection channel cloud push user history small program package update, to be continued ~~~

  2. Forced update getUpdateManager API: the above methods are transparent to developers, small program general mechanism. However, in order to facilitate developers to have sufficient control over the upgrade of the small package, we provide the swan.getUpdateManager update API for developers to choose from. Developers can embed this capability in small packages in case of major release updates or urgent issues that need to be fixed immediately. About swan.getUpdateManager use please snap the link.

conclusion

Many existing mechanisms have been introduced above, and a brain map is attached for your understanding: