tencent cloud

Feedback

Basic Library Introduction

Last updated: 2024-07-12 16:45:16

    Introduction

    The base library acts as a middleware responsible for loading mini programs. It pre-packages many capabilities of the app and the phone (such as Bluetooth, NFC, etc.), allowing developers to use standard components and APIs to develop mini programs.
    You can think of the base library as similar to common web development libraries like React or Lodash. However, it is more specialized because the capabilities of mini programs require support from the SDK. Therefore:
    The base library, like the host app, has its own version number.
    New capabilities added in each version of the base library need to run in specific versions.
    Some capabilities of higher versions of the base library are not compatible with lower version SDKs.
    
    Typically, the base library provides two main parts for mini program developers: components and APIs.
    WXML files in mini programs, when compiled, can render real DOM nodes in the environment provided by the base library.
    APIs like Page and Component used in JS files of mini programs are also exposed globally by the base library.
    The wx.xxx APIs used in mini programs actually call native capabilities (like Bluetooth, WiFi, etc.), and the base library acts as a "bridge" between the mini program and the native container.
    
    In short, the base library mainly handles data binding, provides a component system, event system, communication system, and other framework logic. From the dual-process model perspective, it includes rendering issues of the Virtual DOM in the rendering layer and built-in components and APIs in the logic layer. Additionally, the base library provides supplementary capabilities for mini programs, such as custom components and performance compatibility.
    const {SDKVersion} = wx.getSystemInfoSync(); // fetch jsLib version

    Base library mechanism

    When developing web pages, we often reference third-party JavaScript libraries. Before using the APIs provided by these libraries, we need to include them in our business code.
    
    Similarly, when opening a mini program in an app, we need to load the base library before starting the mini program, and then load the business code. Since the rendering layer and logic layer of mini programs are managed by two threads, when we talk about the base library, it usually includes the WebView base library (rendering layer) and the AppService base library (logic layer).
    
    Before opening any mini program based on TCMPP, the same base library needs to be injected. Therefore, we do not need to package the base library in the mini program's code package. Instead, we need to integrate the TCMPP mini program SDK in the app and introduce the mini program base library through the SDK. Introducing the base library through the SDK has two benefits:
    It can reduce the size of the mini program code package.
    It allows adding capabilities or fixing bugs in the base library without modifying the mini program's code.
    
    Mini program startup
    When you open a mini program, you'll see a loading page that includes the mini program's icon and name. On this page, the base library and code package are downloaded first. Once the downloads are complete, the base library and code package are loaded separately.
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support