# Performance and Experience Optimization
To make the user's answer and call experience more smooth, the key is to shorten the time it takes for the Mini Program to start and some network requests to receive and dial.
The cold start of Mini Programs takes a certain amount of time, especially on equipment with poor performance, and the start time may be too long. Affect the user's experience of making and receiving audio and video calls.
# 1. Small Program Side Startup Performance Optimization
Suggested Developer ReferenceStartup Performance Optimization DocumentOptimize the startup time of Mini Programs.
# 2. Android WMPF Mini Program Preheating (Suggestions)
On the device side WMPF, we provide additionalSmall preheatingThe ability of the user to use the Mini Program in advanceThe Mini Program in the background in the form of no interface to start and resident runningSo that the user can directly cut the Mini Program to the foreground when using it, without the need for a complete cold start process. The process is as follows:
- WMPF After activation, before the user can use the Mini Program, you can call[
warmUpApp
](https://developers.weixin.qq.com/doc/oplatform /Miniprogram_Frame/api/cli/miniprogram/warmUpApp.html)Preheat Mini programs in advance.- Typically, it is recommended to specify path Dialing for the plug-in/Answer the page
plugin-private://wxf830863afde621eb/pages/call-page-plugin/call-page-plugin?isPreLaunch=1
If the developer needs to open other pages when the Mini Program starts (such as the contact list page), they can also specify to warm up other pages.
- Typically, it is recommended to specify path Dialing for the plug-in/Answer the page
- Device side to initiate or answer a call, really need to use the Mini Program, and then call[
launchMiniProgram
](https://developers.weixin.qq.com/doc/oplatform /Miniprogram_Frame/api/cli/miniprogram/launchMiniProgram.html)Incoming normal with query of path Such as startup parameters, you can reuse the preheated environment before the Mini Program pulled to the foreground.- Incoming during preheating and formal use path The path part of the parameter needs to be consistent, query Some may be different. Otherwise, it will trigger the page once more. reLaunch
Mini Program developers need to identify and adapt to the warm-up start situation:
- It is recommended that the developer add a
isPreLaunch=1
Parameter (other names may also be used) that identifies the preheating entry - in App.onShow The event's query In, it is necessary to judge whether there is isPreLaunch。isPreLauntch for 1 When, can be considered as warm-up start, should not initiate a call.
- nothing isPreLaunch Is the normal boot, you can use from the plugin
getPluginEnterOptions()
Get the parameters calledinitByCaller
。
const wmpfVoip = requirePlugin('wmpf-voip' ).default
App({
onShow() {
const options = wmpfVoip.getPluginEnterOptions()
if (options.query.isPreLaunch) {
// Mini Program to warm up the scene, no need to deal with
} else {
// Normal startup scenario, execution of other business logic
}
}
})
Be careful
- Reference No. 4 Section if it is not specified when you close the Mini Program
keepRunning
Parameters are True, the Mini Program needs to be preheated again after closing. - Preheating or cutting the background does not guarantee that the Mini Program will always run. May result because of the system's resource management policies WMPF Be recycled, or when the cutting background exceeds a certain amount of time or resource constraints by the WMPF Take the initiative to clean up Mini programs.
# 3. Android WMPF Mini Program environment preload
If you do the Mini Program warm-up, there is no need for environmental preloading
If the equipment resources are tight and other reasons, it is inconvenient to warm up the Mini Program background, you can also use the [preload](https://developers.weixin.qq.com/doc/oplatform /Miniprogram_Frame/api/cli/miniprogram/preload.html) Interface to preload the Mini Program environment. This interface will only pre-create a basic Mini Program runtime environment and basic Mini Program libraries, and will not start a specific Mini Program.
# 4. Android WMPF Close Mini Program to cut the background
By default, calling the WMPF [closeWxaApp](https://developers.weixin.qq.com/doc/oplatform /Miniprogram_Frame/api/cli/miniprogram/closeWxaApp.html) When the interface closes the Mini Program, it directly destroys the instance of the Mini Program and requires a cold start (or warm up) for the next use.
It is recommended that when the developer closes the Mini Program, the incoming keepRunning
for True, at this time the Mini Program will directly cut the background, the next use can be directly reused, to avoid repeated cold start or repeated preheating.
# 5. Bill pre-acquisition
Calling plug-in initByCaller
Used when initiating the call. deviceToken
and pushToken
Such tickets need to be obtained from the WeChat background, and if they are obtained after the user clicks on them, it may prolong the time it takes to initiate a call.
Developers are advised to prepare these parameters in advance on the front page where the user initiates the call (e.g. contact page, etc.). If the user initiates the call within the validity period of the ticket, they do not need to retrieve it.