# Sub-package pre-download

{% version ('2.3.0', 'text') %} Developer Tools Please use 1.02.1808300 and above and download by clicking here to download .

Developers can configure the framework to automatically pre-download sub-packages that may be needed when entering a Weixin Mini Program page to improve the startup speed of subsequent sub-packages.For independent subpackages , the master package can also be pre-downloaded.

Subcontracting predownloads are currently only supported by configuration and are not supported by calling the API.

VConsole has log information at the beginning ofpreloadSubpackages, which can be used to verify predownloads.

# Configuration method

The pre-download sub-packageing behavior is triggered when entering a page and is controlled by adding thepreloadRuleconfiguration toapagejson.

{
  "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,keyis the page path, andvalueis a pre-download configuration for entering this page. Each configuration has the following items:

field type Required to fill in Default values Introductions
packages StringArray yes nothing Enter the page and pre-download the subcontract'srootorname.__APP__indicates master package.
network String no wifi 在指定网络下预下载,可选值为:

all: 不限网络

wifi: 仅wifi下预下载

# limit

Pages in the same package share a common predownload size limit of 2 M, which is checked when packaged in the tool.

For example, pages A and B are in the same subcontract, and the total size of the subcontract in A is 0.5M, and the maximum size of the subcontract in B is 1.5M.