uni-app WeChat applet: enable on-demand injection of components

uni-app WeChat applet: enable on-demand injection of components

1. Official documents

https://developers.weixin.qq.com/miniprogram/dev/framework/ability/lazyload.html

inject on demand

The base library version 2.11.1 and above supports it, and versions below 2.11.1 are compatible but have no optimization effect. Please use version 1.05.2111300 and above for tool debugging, and version 2.20.1 and above for the basic library.

Normally, when the applet starts, all the JS codes of all code packages (main package, subpackage, plug-in package, extension library, etc.) For custom components, all JS codes of pages and custom components will be executed immediately. This causes a lot of unused code to be injected and executed in the applet runtime environment, which affects the injection time and memory usage.

Starting from the base library version 2.11.1, applets support selective injection of necessary codes through configuration to reduce the startup time and runtime memory of applets.

{
    
    
  "lazyCodeLoading": "requiredComponents"
}

Precautions

  • When on-demand injection is enabled, the applet only injects the custom components and page code needed for the currently visited page. Unvisited pages and custom components not declared on the current page will not be loaded and initialized, and the corresponding code files will not be executed. Developers are requested to confirm that the applet behaves normally after modifying the configuration .
  • After enabling on-demand injection, all components defined in the page JSON configuration and global custom components configured app.jsonin will be considered as dependencies of the page and will be injected and loaded. usingComponentsIt is recommended that developers remove the declarations of unused custom components in JSON in a timely manner , and try to avoid declaring low-usage custom components globally , otherwise the effect of on-demand injection may be affected.
  • Plug-in packages and extension libraries currently do not support on-demand injection. If you need to implement on-demand loading of plug-ins, you can consider placing the plug-in in a subpackage and importing it asynchronously in the form of " subpackage asynchronization " .

2. HBuilder X settings

image-20230723100417040

3. Effect

image-20230723100502596

Guess you like

Origin blog.csdn.net/qq_29689343/article/details/131876652
Recommended