# Subpackage Preload

Start from base library version 2.3.0. Please remaining backward compatible. Download a Weixin DevTools as of version 1.02.1808300.

Developers can configure the framework to automatically preload required subpackages when a user enters a Mini Program page, to speed up the subsequent startup of subpackaged pages. For Independent Subpackages, the main package can also be preloaded.

Subpackages can be preloaded only via configuration.

Log prefixed with preloadSubpackages is available in vConsole to verify the preload status.

# Configuration

Subpackage preload is triggered when a user enters a specific page, and is controlled by adding preloadRule configuration items via app.json.

{
  "pages": ["pages/index"],
  "subpackages": [
    {
      "root": "important",
      "pages": ["index"],
    },
    {
      "root": "sub1",
      "pages": ["index"],
    },
    {
      "name": "hello",
      "root": "path/to",
      "pages": ["index"]
    },
    {
      "root": "sub3",
      "pages": ["index"]
    },
    {
      "root": "indep",
      "pages": ["index"],
      "independent": true
    }
  ],
  "preloadRule": {
    "pages/index": {
      "network": "all",
      "packages": ["important"]
    },
    "sub1/index": {
      "packages": ["hello", "sub3"]
    },
    "sub3/index": {
      "packages": ["path/to"]
    },
    "indep/index": {
      "packages": ["__APP__"]
    }
  }
}

In preloadRule, key is the page path, and value is the preload configuration for entering the page. Each configuration includes the following items:

Field Type Required Default Description
packages StringArray Yes No Indicates root or name of a subpackage preloaded after a user enters a page. __APP__ indicates the main package.
network String No wifi Indicates a specified network over which a subpackage is preloaded. Values:
all: Any network
wifi: Wi-Fi only

# Limits

Pages of the same subpackage share the same maximum preload size of 2 MB, which is verified when the pages are packaged via the DevTools.

For example, Page A and Page B are in the same subpackage. If a subpackage with a total size of 0.5 MB is preloaded on Page A, a maximum of 1.5 MB subpackages can be preloaded on Page B.